-
Notifications
You must be signed in to change notification settings - Fork 2
multilingual
Max Ivak edited this page Apr 2, 2018
·
8 revisions
Languages
- table cms_languages
Page:
- check "Translated" checkbox for the page
- URL: use special symbol
:langin URL
:lang - for home page
:lang/about - for about page
product/:id/description-:lang - product description page
- Edit metadata for each language
- specify template
Template:
- There are two ways of translating content:
- translate the whole template so it will be a separate template file for each language;
- have one template for every language and translate content on a page using blocks and/or resources.
Translated template:
- check "Translated" checkbox
- it will generated files on disk like 'textpages/about.en.html.haml', 'textpages/about.ru.html.haml', etc
- edit content for each language
Resources:
- use translated resources
- go to Admin -> Content -> Languages
- Languages are stored in table 'cms_languages'
- make link
=link_to 'About', site_page_path('about')
it will return URL like '/en/about' or '/ru/about' depending on the current language.
- access current language from view
=params[:lang]
- see resources
Translate pages with URLs like 'http://site.com/:lang/path'
We want to have pages with URLs:
-
/en- home page in English -
/ru- home page in Russian -
/en/about- about page in English -
/ru/about- about page in Russian - etc
To achieve this we will create pages in Admin area:
- Home page with URL:
:lang - About page with URL:
:lang/about
Routes:
- edit
routes.rb - redirect to the default language from root
/:
get '/', to: redirect('/en/')
- redirect to the default language depending on user IP - see