Project

localeapp

0.15
Low commit activity in last 3 years
No release in over a year
Synchronizes i18n translation keys and content with localeapp.com so you don't have to manage translations by hand.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.8
~> 2.0
>= 0
~> 3.3
>= 0

Runtime

>= 0
>= 0.7, < 2
>= 1.7.7
>= 1.8.0
 Project Readme

Locale

Build status Code Climate Security Gem Version

The localeapp gem connects your Rails app to the Locale service on https://www.localeapp.com. Locale makes hand editing translation files something you don't have to do.

The gem hooks into the i18n exception mechanism to send missing translations to the app. When translated content has been added it's automatically pulled down so you can see it straight away.

Security

Though the i18n gem uses YAML as it's default file format it doesn't require serialization of ruby objects. To prevent the kind of security problems detailed in CVE-2013-0156 the localeapp gem will not load any YAML containing the string !ruby/ as of version 0.6.9.

Installation

Note that the API key is actually never written to configuration files generated by the gem, but is expected to be set in the environment as LOCALEAPP_API_KEY.

For convenience, the install command accepts a -e or --write-env-file option that will append the API key to .env file, so that you can use foreman or other tools supporting this convention.

Rails 3+

Add the localeapp gem to your Gemfile and install it:

echo "gem 'localeapp'" >> Gemfile
bundle install

Create a project on Locale and get the api key. Then run:

bundle exec localeapp install <YOUR_API_KEY>

This will check everything looks good and create config/initializers/localeapp.rb for you.

Rails 2.3

Rails 2.3 support has been discontinued after 1.0.2. Please use this version at your own risk if you really want to.

Non rails projects

Install the gem and run:

localeapp install --standalone <YOUR_API_KEY>

This will create a .localeapp directory for your configuration files.

Public projects

Install the gem and run:

localeapp install --github <YOUR_API_KEY>

This will create a skeleton project you can push to <your_gem>-i18n on github. You get a .localeapp directory for your configuration files, a locales directory for the yaml, a .gitignore file that ignores .localeapp and a README.md explaining to translators how to find the project on localeapp.com.

Importing existing content

You can import via localeapp.com or with the command line tool. To import existing translations do:

localeapp push config/locales/en.yml

This will queue importing the file. The projects pages on localeapp.com will automatically refresh so you can see the import progress.

If you've more than one locale to import you can import all files in a directory:

localeapp push config/locales/

Default Rails Translations

Locale will automatically add the standard rails translations when a project is created. If for some reason you don't want these, you can remove them using in the project libraries area on localeapp.com

Automatically sending missing translations

Missing translations are automatically sent only in the development environment by default. When a page is refreshed any missing translations will be sent to localeapp.com.

If you want to disable sending missing translations in the development environment then edit config/initializers/localeapp.rb to include:

config.sending_environments = []

This is just an array, so you can configure it to match send in any environment you wish.

Manually create translations

You can create translations on the command line by running:

localeapp add key.name en:"test content" es:"spanish content"

You must provide at least one translation and the locale code must already exist in the project.

Copy a translation

You can copy a translation on the command line by running:

localeapp cp key.source_name key.destination_name

If the destination key name exists in the project the content is overwritten, otherwise a new key is created.

Automatically pulling translations

There are two ways to do this, one that suits a single developer working the code locally and one where the translations are being pulled down to a staging (or live) server.

Single developer

In this mode the gem pulls any updated translations from localeapp.com at the beginning of each request. This is the default setting so you don't need to do anything special.

Staging server

In this mode you configure the individual listeners to not poll every request and instead run localeapp in daemon mode to fetch updated translations. This is useful when you have more than one listener and don't want them to race to update the translations.

Disabling polling

Edit config/initializers/localeapp.rb to include:

config.polling_environments = []

Run the daemon with:

localeapp daemon

The listeners will automatically reload translations when they see there are new ones. The daemon has two options:

-b will run in the background and put a pid file in tmp/pids/localeapp.pid -i X will change the polling interval to X from it's default five seconds.

Disabling Reloading

Automatic reloading is only enabled in the development environment by default and can be disabled in a similar way to polling and sending:

config.reloading_environments = []

Blacklisting keys and namespaces (Rails only)

To prevent certain missing translations from being sent to the Locale servers - in case of automatically generated keys from a gem for example - you can configure the blacklisted_keys_pattern option with a regular expression.

For example, to prevent all keys containing the word "simple_form" :

config.blacklisted_keys_pattern = /simple_form/

Caching

To prevent localeapp from sending translations every time they are missing, add this config setting:

config.cache_missing_translations = true

Inviting other developers and translators

You can invite other developers and translators via localeapp.com. Developers have access to all the content and all the locales. Translators are restricted to editing only the locales you give them access too.

Adding a locale

If we find an unknown locale during an import we'll add it to your project. You can also add a new locale to a project via localeapp.com. This will create missing translations for every translation key. You will need to restart any listeners completely to pick up the new locale.

Proxies

If you need to go through a proxy server, you can configure it with:

config.proxy = "http://my.proxy.com:8888"

SSL Certificate verification

localeapp.com uses https everywhere but certificate validation is turned off by default. This is because ruby doesn't know how to read the certs from the OSX keychain. You can turn verification on and tell the gem where the latest CA certificates are by adding:

config.ssl_verify = true
config.ssl_ca_file = /path/to/ca_cert.pm

See this article on Ruby Inside for some more details.

Support and feedback

You can contact us via the support link at the bottom of the page or emailing support@localeapp.com

Contributing

See corresponding contributing guidelines.

Known bugs

We are aware about a compatibility issue with JRuby 9.1 and i18n 1.3. Our recommandation so far is to use i18n < 1.3 if you are using JRuby 9.1.

License

Copyright (c) 2014 Locale and other contributors, released under the MIT License.