Internationalization or "I18n" Internationalization Basics i18n—short for "internationalization...
Public Lab is an open community which collaboratively develops accessible, open source, Do-It-Yourself technologies for investigating local environmental health and justice issues.
8 CURRENT | jiteshxyz |
August 23, 2016 16:03
| over 7 years ago
Internationalization or "I18n"Internationalization Basicsi18n—short for "internationalization." (There are 18 letters between the "i" and the "n" in "internationalization.") Internationalization means architecting and developing an application in order to bring support for a second locale—possibly at a future time. The default tool for internationalizing a rails application is with the ruby i18n gem. Basically, the i18n gem creates a directory called config/locales. Rails then stores the application's various languages in a yaml file, such as en.yml for English or fr.yml for French. The I18n gem ships with a feature called variable interpolation that allows you to use variables in translation definitions and pass the values for these variables to the translation method. Example en.yml file:
Example fr.yml file:
Possible ERB code:
The output would be:
Similarly, I18n's translate method could also be used inside model or controller. For example:
Organization of Locale Filesplots2 config/locales directory looks like this:
Using Safe HTML TranslationsKeys with a '_html' suffix and keys named 'html' are marked as HTML safe. When you use them in views the HTML will not be escaped. For example:
For the above combination, the HTML output will be:
SupportFor more information, check out The Official Guide or write to us at plots-dev@googlegroups.com |
Revert | |
7 | jiteshxyz |
August 23, 2016 15:52
| over 7 years ago
Internationalization or "I18n"Internationalization Basicsi18n—short for "internationalization." (There are 18 letters between the "i" and the "n" in "internationalization.") Internationalization means architecting and developing an application in order to bring support for a second locale—possibly at a future time. The default tool for internationalizing a rails application is with the ruby i18n gem. Basically, the i18n gem creates a directory called config/locales. Rails then stores the application's various languages in a yaml file, such as en.yml for English or fr.yml for French. The I18n gem ships with a feature called variable interpolation that allows you to use variables in translation definitions and pass the values for these variables to the translation method. Example en.yml file:
Example fr.yml file:
Possible ERB code:
The output would be:
|
Revert | |
6 | jiteshxyz |
August 23, 2016 15:48
| over 7 years ago
Internationalization or "I18n"Internationalization Basicsi18n—short for "internationalization." (There are 18 letters between the "i" and the "n" in "internationalization.") Internationalization means architecting and developing an application in order to bring support for a second locale—possibly at a future time. The default tool for internationalizing a rails application is with the ruby i18n gem. Basically, the i18n gem creates a directory called config/locales. Rails then stores the application's various languages in a yaml file, such as en.yml for English or fr.yml for French. The I18n gem ships with a feature called variable interpolation that allows you to use variables in translation definitions and pass the values for these variables to the translation method. Example en.yml file:
|
Revert | |
5 | jiteshxyz |
August 22, 2016 15:32
| over 7 years ago
Internationalization or "I18n" |
Revert | |
4 | jiteshxyz |
August 22, 2016 15:31
| over 7 years ago
Internationalization or "I18n"Internationalization Basicsi18n—short for "internationalization." (There are 18 letters between the "i" and the "n" in "internationalization.") Internationalization means architecting and developing an application in order to bring support for a second locale—possibly at a future time. The default tool for internationalizing a rails application is with the ruby i18n gem. Basically, the i18n gem creates a directory called config/locales. Rails then stores the application's various languages in a yaml file, such as en.yml for English or fr.yml for French. The I18n gem ships with a feature called variable interpolation that allows you to use variables in translation definitions and pass the values for these variables to the translation method. Example en.yml file:
Example fr.yml file:
Possible ERB code: ``` <%= I18n.translate("hello_world", :locale => "en") %> <%= I18n.translate("hello", :locale => "en", :name => "James") %> <%= I18n.translate("hello_world", :locale => "fr") %> <%= I18n.translate("hello", :locale => "fr", :name => "James") %>
app/controllers/home_controller.rbclass HomeController < ApplicationController def index flash[:notice] = I18n.translate('hello_world') end end ``` Organization of Locale Filesplots2 config/locales directory looks like this:
Using Safe HTML TranslationsKeys with a '_html' suffix and keys named 'html' are marked as HTML safe. When you use them in views the HTML will not be escaped. For example:
``` app/views/home/index.html.erb<%= raw t('welcome') %>
``` For the above combination, the HTML output will be: welcome! SupportFor more information, check out The Official Guide or write to us at plots-dev@googlegroups.com |
Revert | |
3 | jiteshxyz |
August 22, 2016 15:19
| over 7 years ago
Internationalization or "I18n"Internationalization Basicsi18n—short for "internationalization." (There are 18 letters between the "i" and the "n" in "internationalization.") Internationalization means architecting and developing an application in order to bring support for a second locale—possibly at a future time. The default tool for internationalizing a rails application is with the ruby i18n gem. Basically, the i18n gem creates a directory called config/locales. Rails then stores the application's various languages in a yaml file, such as en.yml for English or fr.yml for French. The I18n gem ships with a feature called variable interpolation that allows you to use variables in translation definitions and pass the values for these variables to the translation method. Example en.yml file:
Example fr.yml file:
Possible ERB code: ``` <%= I18n.translate("hello_world", :locale => "en") %> <%= I18n.translate("hello", :locale => "en", :name => "James") %> <%= I18n.translate("hello_world", :locale => "fr") %> <%= I18n.translate("hello", :locale => "fr", :name => "James") %>
app/controllers/home_controller.rbclass HomeController < ApplicationController def index flash[:notice] = I18n.translate('hello_world') end end ``` Organization of Locale Filesplots2 config/locales directory looks like this:
Using Safe HTML TranslationsKeys with a '_html' suffix and keys named 'html' are marked as HTML safe. When you use them in views the HTML will not be escaped. For example:
``` app/views/home/index.html.erb<%= raw t('welcome') %>
``` For the above combination, the HTML output will be: welcome! SupportFor more information, check out The Official Guide or write to us at plots-dev@googlegroups.com |
Revert | |
2 | jiteshxyz |
August 22, 2016 15:18
| over 7 years ago
Internationalization or "I18n"Internationalization Basicsi18n—short for "internationalization." (There are 18 letters between the "i" and the "n" in "internationalization.") Internationalization means architecting and developing an application in order to bring support for a second locale—possibly at a future time. The default tool for internationalizing a rails application is with the ruby i18n gem. Basically, the i18n gem creates a directory called config/locales. Rails then stores the application's various languages in a yaml file, such as en.yml for English or fr.yml for French. The I18n gem ships with a feature called variable interpolation that allows you to use variables in translation definitions and pass the values for these variables to the translation method. Example en.yml file:
|
Revert | |
1 | jiteshxyz |
August 22, 2016 15:18
| over 7 years ago
Internationalization or "I18n"Internationalization Basicsi18n—short for "internationalization." (There are 18 letters between the "i" and the "n" in "internationalization.") Internationalization means architecting and developing an application in order to bring support for a second locale—possibly at a future time. The default tool for internationalizing a rails application is with the ruby i18n gem. Basically, the i18n gem creates a directory called config/locales. Rails then stores the application's various languages in a yaml file, such as en.yml for English or fr.yml for French. The I18n gem ships with a feature called variable interpolation that allows you to use variables in translation definitions and pass the values for these variables to the translation method. Example en.yml file:
Example fr.yml file:
Possible ERB code: ``` <%= I18n.translate("hello_world", :locale => "en") %> <%= I18n.translate("hello", :locale => "en", :name => "James") %> <%= I18n.translate("hello_world", :locale => "fr") %> <%= I18n.translate("hello", :locale => "fr", :name => "James") %>
app/controllers/home_controller.rbclass HomeController < ApplicationController def index flash[:notice] = I18n.translate('hello_world') end end ``` Organization of Locale Filesplots2 config/locales directory looks like this:
Using Safe HTML TranslationsKeys with a '_html' suffix and keys named 'html' are marked as HTML safe. When you use them in views the HTML will not be escaped. For example:
``` app/views/home/index.html.erb<%= raw t('welcome') %>
``` For the above combination, the HTML output will be: welcome! SupportFor more information, check out The Official Guide or write to us at plots-dev@googlegroups.com |
Revert |