| Start |
|---|
| I18n with arguments You can pass parameters to I18n And get the following output: |
| Translating ActiveRecord model attributes
If you're using Model translations allow you to translate your models' attribute values, for example: After you defined your model attributes that need to be translated you have to create a translation table, through a migration. For this migration you need to use You may also pass options for specific options, like: In case you already have any existing data in your needing translation columns, you can easily migrate it to the translations table, by adjusting your migration: Make sure you drop the translated columns from the parent table after all your data is safely migrated. To automatically remove the translated columns from the parent table after the data migration, add the option You may also add new fields to a previously created translations table: |
| Pluralization You can let I18n handle pluralization for you, just use You need to set up your locale file like this: And then use the key you just created by passing the |
| Set locale through requests In most cases, you may want to set URL-basedThe Or To achieve the latter, you need to edit your By doing this, visiting Session-based or persistence-basedThis assumes the user can click on a button/language flag to change the language. The action can route to a controller that sets the session to the current language (and eventually persist the changes to a database if the user is connected) You have to define sanitize_language_param with your list of available languages, and eventually handle errors in case the language doesn't exist. If you have very few languages, it may be worth defining them like this instead: Note: don't forget to add some routes to your Default LocaleRemember that you need to set your application default locale. You can do it by either setting it in or by creating an initializer in the |
| Get locale from HTTP request Sometimes it can be useful to set your application locale based upon the request IP. You can easily achieve this using First, add
Beware that this will not work in Limitations and alternatives
To address these, it can also be worth considering: 1. An offline solutionUsing a gem like 2. Use CloudFlarePages served through CloudFlare have the option of being geocoded transparently, with the country code being added to the header ( |
Use I18n with HTML Tags and Symbols Note the addition of extra And in Views, |
| Use I18n in views Assuming you have this YAML locale file: and you want to display your title string, you can do this Syntax
|
Read Article
https://develop.horje.com/learn/1434/reference