
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
i18n-csv_translation
Advanced tools
Ever needed to add a new locale to an existing (Rails) project with dozens of .yml files? Too afraid to give all files to the customer or translation service and hope they do not mess up the YAML format?
This gem allows you to export all i18n keys and values to one CSV file. With this the values can be easily translated and later reimported into your project. The new translations are saved in a filename similar to the original one (only the locale is replaced).
Add this line to your application's Gemfile in the development group because you will need it only locally:
group :development do
gem "i18n_csv", require: false
end
And then execute:
$ bundle
Or install it yourself as:
$ gem install i18n-csv_translation
Write in a (Rails) console or script:
require "i18n/csv-translation"
exporter = I18n::CsvTranslation::Exporter.new
exporter.export(path: "path-to-your-locales-directory", output: "my_translations.csv", files: "*.yml")
Note: The gem expects only one locale in each file. If you want to export only English to have it translated you can either
give a files param like files: "en.*.yml"
or use a block (see below) to determine if the files content should be processed.
If you wish a different csv column separator give it as option:
I18n::CsvTranslation::Exporter.new(col_sep: "\t")
With a block you can decide if the translation file should be processed
exporter.export(path: "path-to-your-locales-directory", output: "my_translations.csv") do |file|
!file.include? "admin"
end
Ignores all files with "admin" in the name.
Given you got a csv with translated values for a new locale, lets say German.
The import process works only if the first two columns on the csv file haven't been touched by the translaters. The first column holds the file name of the original translation file, without the locale. The second one is the translation key, again without locale.
Creating new translation files can be done like this:
require "i18n/csv-translation"
importer = I18n::CsvTranslation::Importer.new
importer.import input: "path_to_translated_csv_file", path: "path_for_new_translation_files", new_locale: "de"
Given you had two English translation files:
config/locales/en.users.yml
config/locales/en.addresses.yml
After the import you would have these two new German translation files:
de.users.yml
de.addresses.yml
With all keys and values in their respective files, e.g. "de.users.name" in de.users.yml, "de.addresses.street" in de.addresses.yml.
The translated csv file has a custom col sep?
importer = I18n::CsvTranslation::Importer.new(col_sep: "\t")
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Bug reports and pull requests are welcome on GitHub at https://github.com/swelther/i18n-csv_translation.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that i18n-csv_translation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.