We need to start delivering dynamic content in multiple languages with our different apps.
There are two types of localisation that should be considered: UI localisation and Content localisation. UI localisation is the language the interface is delivered in (static text) while Content localisation is the language content is viewed/edited (Rails model)
We basically have 3 type of apps
Mobile apps - hits an API endpoints for CRUD operations
Client Web app - built with backbone.js so also using API endpoints for CRUD operations via backbone models/collections
Admin web app - built using activeadmin (https://github.com/activeadmin/activeadmin)
I should note we are using Rails 3.2, ActiveAdmin 0.6.6 (upgrading needed but not priority :))
To localise the content, we are looking the globalize gem (https://github.com/globalize/globalize)
There doesn't seem to be any issues using globalize when interfacing with the API endpoints. We can use the Accept-Language header and set the I18n.locale property in a before_filter and everything seems to work fine. This means the Mobile apps and Client Web app should be covered.
For ActiveAdmin, this becomes a bit more difficult. For the ActiveAdmin app, we would like to deliver the UI static text in the user's preferred language while allowing them to switch between languages for the content.
The globalize gem leverages the I18n.locale property to determine which locale to update/read for the content translations. Since ActiveAdmin is not using AJAX, setting I18n.locale will also affect the UI static text.
At the moment, this is not a big deal as we only have one locale for the UI (config/locales only contain en yml files). This means we can use the method described at https://github.com/activeadmin/activeadmin/wiki/Specifying-locale and set the I18n.locale property to update the correct dynamic content, via globalize, while the UI interface will continue to be delivered in English
However, thinking to the future, where we potentially add additional languages for the UI, I'm looking for ideas of how to keep the UI locale and the content locale separate. Other languages, such as Java and C#, do this with different properties on their I18n equivalent library but Rails doesn't seem to embrace this
Thoughts?
Thanks in advance
after further investigation, I ended up using activeadmin-globalize gem. Initially, I didn't think it was compatible with the globalize gem based on the documentation but it is
Related
We're using Rails with I18n for a web application running for users in multiple countries. To handle different languages we're setting the locale based on the TLD. Now, we have an important customer in one country that requires custom translations. To handle this, we would like to overlay a few translations for that specific customer.
Right now we're loading the locales as usual, but also add a folder to the I18n.load_path if the session belongs to the specific customer and then run I18n.backend.reload!. This works well, and we only have to add the keys that needs custom translations for the customer in question. What's less great is that this changes the translations for everybody using the same language.
What's the recommended way to do this in Rails?
I sorted this out by adding a custom locale for which I added a fallback to the language in question. Works well.
How can I include a different set of assets (CSS and JavaScript) for AngularJS views designed for phones and AngularJS views designed for desktop from a Rails API? The default template (application.html.erb or index.html) would typically only be loaded once, with the initial request, because it's an AngularJS application, so I do not think the usual desktop vs. mobile solutions for Rails apps will work.
Specifically, I am trying to combine a desktop app that uses AngularJS, Bootstrap, and jQuery with a mobile app that uses AngularJS and Ionic. The two apps will mostly have shared code, except for the views. The views will be very different, so a responsive approach will not be enough. I have not been able to find much guidance on this at all. Any help will be greatly appreciated.
Rails 4.1 offers variants so that you can have different view templates depending on the display type. Here's a more thorough example. It's really recent so there's not a lot out there about them yet.
If you're not on 4.1, you can look at using the Mobylette gem to achieve the same thing. You can then also have a completely different application.mobile.erb that includes different assets.
For flipping between which assets you're including, you can also take a look at this (the helper method part), but this won't address the issue with different sets of views across the board:
Mobile style switching in Rails 3, helper method vs media queries
Hello everyone :D I've just started learning Rails and currently I have one concern.
I am building a Rails web site which needs to be translated to 4 languages. What would be the most practical and convenient method to do it?
I've read the main goal would be to make separate folders for each language and copy all the views for each language. But I would still have notice messages on English inside my controller so how would I handle that. Routes are also my concern. Should I have 4 different routes for 4 different translated Views.
What do you recommend to handle this problem? I didn't find anything concrete online.
Thank you for your suggestions!
for your notice messages you can do
def create
if user.save
flash[:notice] = t(:user_was_successfully_created)
redirect_to users_users_path
else
render :new
end
end
you should not have 4 different routs
Rails Internationalization (I18n) API
take a look at this link http://guides.rubyonrails.org/i18n.html
Rails Internationalization (I18n) API
The Ruby I18n (shorthand for internationalization) gem which is shipped with Ruby on Rails (starting from Rails 2.2) provides an easy-to-use and extensible framework for translating your application to a single custom language other than English or for providing multi-language support in your application.
The process of "internationalization" usually means to abstract all strings and other locale specific bits (such as date or currency formats) out of your application. The process of "localization" means to provide translations and localized formats for these bits.1
So, in the process of internationalizing your Rails application you have to:
Ensure you have support for i18n.
Tell Rails where to find locale dictionaries.
Tell Rails how to set, preserve and switch locales.
In the process of localizing your application you'll probably want to do the following three things:
Replace or supplement Rails' default locale — e.g. date and time formats, month names, Active Record model names, etc.
Abstract strings in your application into keyed dictionaries — e.g. flash messages, static text in your views, etc.
Store the resulting dictionaries somewhere.
This guide will walk you through the I18n API and contains a tutorial on how to internationalize a Rails application from the start.
After reading this guide, you will know:
I am writing a site with more than one language, is there any easy way or technique to reduct the workload of changing which text to another language.I have an idea, but I don't know whether it is suitable or easy enough. I create a XML that contain all the text in my web, when the user change their language, my program will base on the language the user choose, and get the suitable tags from the XML, and fill in the page. What do you think? or maybe is there any more easy way to do?
(Assuming I am using RoR, if suggest any gems.)
Check out Rails Internationalization (I18n) API:
The Ruby I18n (shorthand for
internationalization) gem which is
shipped with Ruby on Rails (starting
from Rails 2.2) provides an
easy-to-use and extensible framework
for translating your application to a
single custom language other than
English or for providing
multi-language support in your
application.
I wrote a blog post about "Scoping By Locales". It suggests to put all your content in the database and when you want to fetch it, use the I18n API to set the user's locale to be their language and the fetcher will default to that language.
While I have experience developing Rails apps in English, I am a blank slate when it comes to handling globalization, so please don't shoot me in the head if my question 'doesn't make sense' :)
I have been asked to add multi language feature to a part of a Rails app that I am working on. Initially its only going to be 2 languages, French and German. The content that will be translated (which is in English now) is rendered using partials at the moment hence I am getting a bit inclined on creating partials with different languages and then based on the users language selection call the relevant partial - Would you recommend this approach?
Although it seems a heavy weight solution for this particular purpose, but I am also looking at the Rails Globalize plugin. This seems to appeal if I look at the long term gains, something like what if later I am asked to translate the entire app.
Any insights on what would be a proper structured approach to handle globalization in Rails?
Many Thanks
Have you had a look at the i18n (internationalization) API that is in Rails itself as of 2.2? It makes it easy to store your language translation files as .yml files, so a fr.yml and a de.yml or whatever. It also steps through different approaches of making languages accessible via browser prefs, or URLs, subdomains, etc. In your HTML template files you use symbols to specify the keys for the string you've translated. At least in my basic usage and testing, it was very easy to work with.
I preffer using translator instead of Rail's i18n, since the former handles "scoping of translation" automatically. I recommend you give it a look.
This is a great article on how to use Ruby's GetText to localise you Rails App.