Code Monkey home page Code Monkey logo

i18n-docs's Introduction

i18n-docs

Build Status Code Climate Test Coverage Issue Count Dependency Status

i18n-docs is a ruby gem that helps you to keep translations stored in Google Docs. This makes it easier for translators and project members to coordinate changes and updates. In addition, the standard features of Google Docs are super handy for this process: revision tracking, authorization, publishing, etc.

Although we use it with Google Docs, it could be used with any CSV file.

this gem is currently in use and tested with Rails 3.1. It probably works with other 3.x versions, but probably not 2.x at the moment.

Features

  • download translations from multiple Google spreadsheets and store to YAML files
  • import/export YAML files with a Google Spreadsheet
  • check YAML files for missing translations (rake i18n:find_missing_keys)

Tests

Verify the quality of this gem by checking out this repo and running:

bundle install
rake test

Usage

Configuration

Add the GEM to your project:

gem 'i18n-docs'

Create a configuration file in config/translations.yml:

files:
  navigation.yml: "https://docs.google.com/spreadsheet/pub?key=ab43...34f3&single=true&gid=0&output=csv"
  forms.yml: "https://docs.google.com/spreadsheet/pub?key=0Ap...XveWc&single=true&gid=0&output=csv"
  ... etc ...

Rails

Finally, let Rails know what locales you will be using. Add this to config/application.rb:

module Web
  class Application < Rails::Application
    # add yml path
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*', '*.yml').to_s]
    # locals to support:
    config.i18n.available_locales = [:en,:de,:it,:fr]
  end
end

This defines which languages and translation files to import from a Google Spreadsheet. The content of the Spreadsheet URL is stored to a file called e.g. example1.yml within folders config/locales/en and all other detected locales.

Non Rails

Load rake tasks in your Rakefile:

require 'i18n-docs'

spec = Gem::Specification.find_by_name 'i18n-docs'
load "#{spec.gem_dir}/lib/tasks/store_translations.rake"

Create environment task in your Rakefile:

task :environment do
  ...
end

The minimal scope of this task is to set up I18n.available_locales.

Translations will be stored under config/locales in project root directory. Don't forget to setup I18n accordingly:

I18n.load_path = Dir[File.join(MyProject.root, 'config', 'locales', '**', '*.yml')]

And to load them:

I18n.backend.load_translations

Rake Tasks

Following Rake tasks are added by the GEM to your Rails project:

  • rake i18n:export_translations Export all language files to CSV files (ENV 'locale' have to set for non-'en' locales else only files contained in 'en' folder are considered)
  • rake i18n:import_translations Download translations from Google Spreadsheet and save them to YAML files.
  • rake i18n:missing_keys Find and list translation keys that do not exist in all locales

Setup at Google Docs

  • At Google Docs, create a new spreadsheet for your translations. The first column is the translation key, the other columns are the languages: screenshot
  • use option File -> Publish To the Web screenshot
  • use get a link to generate a unique url that points to the CSV spreadsheet screenshot
  • From now on you should only update translations in Google Docs and run rake i18n:import_translations in the application to get changes. You can also export your

Configuraiton

You can include a set of substitions for preprocessing the CSV after downloading it and before parsing it. Here is an example that replaces non-breaking spaces with normal ones.

files:
  navigation.yml: "https://docs.google.com/spreadsheet/pub?key=ab43...34f3&single=true&gid=0&output=csv"

substitutions:
  - from: "\u00A0"
    to: ' '

Error Handling

I case of the error OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed when running rake i18n:import_translations Follow this: http://stackoverflow.com/questions/12562697/opensslsslsslerror-ssl-connect-returned-1-errno-0-state-sslv3-read-server-ce?answertab=active#tab-top

Todo

Pull requests welcome!

  • create mocked tests that do not have to download our sample CSV files
  • automate the creation of files in config/locales
  • automate the detection of which languages are supported
  • validate use with rails 2.x, other 3.x versions

CHANGELOG

0.1.0

  • usable outside of rails

0.0.10

  • rename module to be inline with the gem-name
  • various cleanups

0.0.9

  • add version.rb
  • content downloaded is forced to UTF-8
  • translation keys read are not downcased anymore
  • fixes a bug when loading documents with an empty key
  • create tmp directory if it does not exist
  • strip spaces from keys

0.0.7

  • YANKED from rubygems.org, sorry

0.0.7

  • get in sync with Rubygems.org version

0.0.4

  • update docs, license. Push to Rubygems.org.

0.0.3

  • open sourced: changed name and description.

0.0.2

  • removed loading of awesome_print from the rake task. It was breaking download

Credits/License

This gem is sponsored by local.ch. It is licensed under the MIT license. If you're a ruby developer and want to work with us in Switzerland, please check out our jobs page.

i18n-docs's People

Contributors

aaronchi avatar abcdea avatar averethel avatar batiste avatar coorasse avatar eduardschaeli avatar firemind avatar geku avatar gonzalocal avatar hiphapis avatar huerlisi avatar ivanjovanovic avatar kitop avatar kot-begemot avatar lwe avatar rnestler avatar ryabrody avatar schmijos avatar skaestle avatar somebox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

i18n-docs's Issues

Ability to use YAML aliases

I use some concerns, e.g. Addressable, in my code and would like to avoid having these (repeated) fields appear many times in my translations speadsheet. I want to use YAML aliases to achieve this and so I'd like to have those aliases in the Google Doc and have them imported correctly.

I would like my final YAML to look as follows:

en:
  aaa:
    tables: &table Table
  activerecord:
    concerns:
      addressable: &addressable
        address: Address
      logoable: &logoable
        logo: Logo
    models:
      some_model:
        table: *table

Note table alias has a value on the same line, whereas addressable includes everything below it.

To achieve that, my google doc to looks as follows:

key en de
aaa.tables &table Table &table Tabelle
activerecord.concerns.addressable &addressable &addressable
activerecord.concerns.addressable.address Address Addresse
activerecord.concerns.logoable &logoable &logoable
activerecord.concerns.logoable.logo Logo Logo
activerecord.models.some_model.table *table *table

no such file to load -- i18n/docs

For some reason I get this error now (using bundler 1.1.3)

gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in `require': no such file to load -- i18n/docs (LoadError)
    from /Users/kmandrup/.rvm/gems/ruby-1.8.7-p358@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:74:in `require'
    from /Users/kmandrup/.rvm/gems/ruby-1.8.7-p358@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `each'
    from /Users/kmandrup/.rvm/gems/ruby-1.8.7-p358@global/gems/bundler-1.1.3/lib/bundler/runtime.rb:55:in `require'
    from /Users/kmandrup/.rvm/gems/ruby-1.8.7-p358@global/gems/bundler-1.1.3/lib/bundler.rb:119:in `require'
    from /Users/kmandrup/work/repos/circle/htc_one/config/application.rb:13

I resolved it by explicitly declaring which file to require.

`gem 'i18n-docs', '~> 0.1.2', :require => 'i18n-docs'``

Very strange indeed!

Don't downcase locale

sv-SE is a valid locale, but things get downcased, which results in sv-se and an error

Make it possible to use en.yml without subdirectories

I just tried to use this handy gem to edit translations via google docs - seems to be very good work! I have one problem with the approach of translations.yml: As far as I understand the code/ docs, i18n-docs forces me to use subdirectories like config/locales/:locale/*.yml. Different projects I am working for are using different directory structures, e.g. one big config/locales/:locale.yml or something like config/locales/mail/:locale.yml.

I would like propose a different approach for specifying relevant files translations.yml. What do you think about something like:

files:
  # config/locales/en.yml, config/locales/de.yml, ...
  :locale.yml: "http://docs.google.com/doc1"
  # config/locales/en/navigation.yml, config/locales/de/navigation.yml, ...
  :locale/navigation.yml: "http://docs.google.com/doc2"

Using :locale as a placeholder for de|en|ru|... should provide much more flexibility. What do you think about this approach? Is it worth in your opinion that I start working on this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.