Is there a quick way to add translation key to all locales - ruby-on-rails

There are translations in 5 languages in my app. Each language has one corresponding file. Adding new translation key in every one of them by hand is very inefficient. How do you solve this problem? Maybe someone has written script for or know Rails command for this purpose?

You can manage this translations and keep all keys in sync between with this gem i18n-tasks. This gem also support auto fill missing keys.
i18n-tasks health
So all you had to do is add one key to one file, and auto fill missing keys in other files.
i18n-tasks add-missing

Related

Where can I store non-localizable fixed strings in rails?

I have some url templates that I use in my app - they are not localizable strings, so config/locales/en.yml does not seem like the best place for them - where do I store these? For example, "http://www.example.com/apps?id=" is one such string.
I know there are several approaches possible (a constants file in the lib folder, or using rails configuration in rails4, or some config gem like configatron), but what is the'right' way?
I don't know that there is "a right way" - the new 'x' configuration option system in Rails 4 seems to be the most "Railsy" solution out there.
I personally think it is totally okay to have a GlobalConstants module defined in an initializer or a file in the lib directory. Put all your global constants in there and be diligent about using them throughout your app where needed.
For projects where there's a mix and match of i18n strings I like having a "base" i18n file and then using the override system to create a sort of inheritance chain between the i18n files. That's not always the appropriate solution but I've had it work out quite well a few times.
Hope that helps you.
As you said there are many solutions and it dependence on usage.
You can store them in environment variables.
dotenv gem help you handle it easier:
https://github.com/bkeepers/dotenv

i18n language files. How to manage missing and unused keys

I have a Rails/Angular webapp. We use two different methods to translate our app: Ruby Globalize i18n with the corresponding yml language files, and angular-translate with the corresponding json language files. Managing language files can be a pain. I just found the i18n-tasks gem on github to help find missing and unused keys in my yml language files. It works great! Does anyone know of a similar static analysis tool to help manage json language files? Is there a better way to do this?
As I write this I am wondering if there is some sort of i18n transpilation that I could do. Keep a single language file and generate the yml and json from that.
Features wanted:
sort keys alphabetically
delete unused keys in all language files
add missing keys in all language files
i18n-tasks already supports JSON, but you would need to write a custom scanner to detect usages of angular-translate. See the custom scanner example.

rails i18n, the best way to manage localization

I'm using http://guides.rubyonrails.org/i18n.html for localization. Looks like that the only solution for updating localization is to update yml files. May be there are some solutions or gems which adds ability to update localization via application. For example we can include some gem and update localization files from our app. Is there some solutions for that?
Shameless plug for my own product here, but check out http://www.localeapp.com for a solution that works with YAML files out of the box.
Take a look at Globalize 3. It stores the translation/localization data in the database. There's also a gem to hook it up with ActiveAdmin.
Also, while you're at it, don't miss the rails-i18n gem mentioned in the guide. It translates Rails itself into many languages, so you don't have to do it yourself.
There is a great railscast to manage i18n through Redis.

Rails tool to search for untranslated strings using yaml locale files

Is there a way to look up all keys used in the rails application and add the untranslated keys to the different yaml locale files?
The tool should scan all the helpers, controllers, views, ... to look for keys being used. Next it should check whether the key is already added to the different locale yaml files.
I'm using the I18n that ships default with Rails.
Update: I'm kind of searching for a rake task that will just search my app for translations keys followed by a look up in the yaml locale files.
Do you mean something like i18n-tasks?
https://github.com/glebm/i18n-tasks
This gem analyses code statically for key usages, such as
I18n.t('some.key'), in order to:
Report keys that are missing or unused.
Pre-fill missing keys, optionally from Google Translate or DeepL Pro.
Remove unused keys.
For finding "untranslated" entries, I believe that any sufficiently advanced diff tool will do (you actually want to just filter the similarities, hiding differences.)
However, please keep in mind that this way you will only find the strings that are exactly the same as English. In other words it doesn't mean that they will be untranslated - some of them might sound exactly the same as English in a target language.
To actually make sure that something is or is not translated, I would recommend using Translation Memory. That will put you in control. However, for small projects it might be an overkill.

Best options for translating a rails app

Since there are so many options there available for internationalization of a rails app, which gems or plugins are the best (today) for adding i18n support to a rails app.
Im using I18n bundled with rails for the application messages, button labels, and model attribue names.
But I also need to let the users to input content and the translated version of the content, but there are so many options for this right now that I don't really know which one to use.
We at Mynewsdesk (the guys behind the translate plugin) has moved on, now we're using Web Translate It to manage our locales. We've bloged about our translation workflow.
I like this one:
https://www.github.com/mynewsdesk/translate
because it has a nice webGUI for translating new/changed strings

Resources