i18n language files. How to manage missing and unused keys - ruby-on-rails

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.

Related

Is there a quick way to add translation key to all locales

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

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

Iterating through and parsing Files in Ruby/Rails

Can someone point me to some documentation/libraries for working with files in a Rails app?
Specifically I need to scan folders for files and for each one read & parse some data from it. I've not done this in Ruby before so not sure where to look.
Thanks!
Parsing files is very easy in Ruby. To do it in Rails, you simply use the Ruby file libraries. Without knowing what you want to do I can't give you any examples, but I can point you to the Ruby API.
File: http://www.ruby-doc.org/core-1.9.3/File.html
Directory: http://www.ruby-doc.org/core-1.9.3/Dir.html

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.

Ruby libraries for parsing .doc files?

I was just wondering if anyone knew of any good libraries for parsing .doc files (and similar formats, like .odt) to extract text, yet also keep formatting information where possible for display on a website.
Capability of doing similarly for PDFs would be a bonus, but I'm not looking as much for that.
This is for a Rails project, if that helps at all.
Thanks in advance!
Apache's POI is a very popular way to access Word and Excel documents. There's a Ruby POI binding that might be worth investigating, but it looks like you'll have to build it yourself. And the API doesn't seem very Ruby-like since it's virtually a direct port from the Java code. And it seems to only have been tested against Ruby 1.8.2.

Resources