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.
Related
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
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
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.
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
I only want to support German and English for a starter.
As I see it I can easily limit this in the spree core locales.rb, or in the localization extension by simply deleting the locale files.
But this doesn't quite seem right. I would like to configure it form my site extension, without basically forking spree. Can someone tell me how I can set AVAILABLE_LOCALES from there?
You can change the AVAILABLE_LOCALES in config/initializers/locales.rb. Obviously usually it's not necessary to have too many localisations. Simply just change the code, which by default collects all locales available.
You might want something like this:
require 'spree/extension'
all_locale_paths = Spree::ExtensionLoader.load_extension_roots.dup << SPREE_ROOT
AVAILABLE_LOCALES = {'en-GB'=>'English', 'de'=>'Deutsch'}