All Projects → webhippie → gettext_i18n_rails_js

webhippie / gettext_i18n_rails_js

Licence: MIT License
Extends gettext_i18n_rails making your .PO files available to client side javascript as JSON

Programming Languages

ruby
36898 projects - #4 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to gettext i18n rails js

Ngettext
A cross-platform .NET implementation of the GNU/Gettext library.
Stars: ✭ 172 (+514.29%)
Mutual labels:  i18n, gettext
Tempura
Pure Clojure/Script i18n translations library
Stars: ✭ 211 (+653.57%)
Mutual labels:  i18n, gettext
Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (+525%)
Mutual labels:  i18n, gettext
Ordinalize full
Turns a number into an ordinal string such as first, second, third or 1st, 2nd, 3rd.
Stars: ✭ 6 (-78.57%)
Mutual labels:  i18n, rubygem
rails
Rails translation made _('simple').
Stars: ✭ 65 (+132.14%)
Mutual labels:  i18n, gettext
Aeiou
i18n scripts
Stars: ✭ 24 (-14.29%)
Mutual labels:  i18n, gettext
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+9610.71%)
Mutual labels:  i18n, gettext
wp-l10n-validator
Gettext localization validator for WordPress
Stars: ✭ 17 (-39.29%)
Mutual labels:  i18n, gettext
Kotsu
✨ Clean, opinionated foundation for new projects — to boldly go where no man has gone before
Stars: ✭ 48 (+71.43%)
Mutual labels:  i18n, gettext
msgtools
Tools for Developing Diagnostic Messages
Stars: ✭ 18 (-35.71%)
Mutual labels:  i18n, gettext
Django Rosetta
Rosetta is a Django application that eases the translation process of your Django projects
Stars: ✭ 806 (+2778.57%)
Mutual labels:  i18n, gettext
stone.js
gettext-like client-side Javascript Internationalization Library
Stars: ✭ 20 (-28.57%)
Mutual labels:  i18n, gettext
Gettext
PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
Stars: ✭ 578 (+1964.29%)
Mutual labels:  i18n, gettext
Gettext Go
🆎 GNU gettext for Go (Imported By Kubernetes)
Stars: ✭ 66 (+135.71%)
Mutual labels:  i18n, gettext
Gotext
Go (Golang) GNU gettext utilities package
Stars: ✭ 292 (+942.86%)
Mutual labels:  i18n, gettext
Glotpress Wp
🌍 🌎 🌏 GlotPress is a WordPress plugin to let you set up your own collaborative, web-based software translation tool.
Stars: ✭ 205 (+632.14%)
Mutual labels:  i18n, gettext
polib
Pure python library to manipulate, create, modify gettext files (pot, po and mo files).
Stars: ✭ 34 (+21.43%)
Mutual labels:  i18n, gettext
rubocop-i18n
RuboCop rules for detecting and autocorrecting undecorated strings for i18n (gettext and rails-i18n)
Stars: ✭ 32 (+14.29%)
Mutual labels:  i18n, gettext
alternate
Plug and Phoenix helpers to localize your web app via the URL
Stars: ✭ 26 (-7.14%)
Mutual labels:  i18n, gettext
pH7-Internationalization
🎌 pH7CMS Internationalization (I18N) package 🙊 Get new languages for your pH7CMS website!
Stars: ✭ 17 (-39.29%)
Mutual labels:  i18n, gettext

gettext_i18n_rails_js

Test Status Join the Matrix chat at https://matrix.to/#/#webhippie:matrix.org Codacy Badge Gem Version

Extends gettext_i18n_rails, making your .PO files available to client side javascript as JSON. It will find translations inside your .js, .coffee, .handlebars and .mustache files, then it will create JSON versions of your .PO files so you can serve them with the rest of your assets, thus letting you access all your translations offline from client side javascript.

Versions

For a list of the tested and supported Ruby and Rails versions please take a look at the wokflow.

Installation

gem "gettext_i18n_rails_js", "~> 1.2"

Versioning

This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.

As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.

For example:

spec.add_dependency "gettext_i18n_rails_js", "~> 1.2"

Usage

Set up you rails application with gettext support as usual, afterwards just execute the following rake task to export your translations to JSON:

rake gettext:po_to_json

Per default this will reconstruct the locale/<lang>/app.po structure as javascript files inside app/assets/javascripts/locale/<lang>/app.js

The gem provides the Jed library to use the generated javascript files. It also provides a global __ function that maps to Jed#gettext. The Jed instance used by the client side __ function is pre-configured with the lang attribute specified in your main HTML tag. Before anything, make sure your page's HTML tag includes a valid lang attribute, for example:

%html{ manifest: "", lang: I18n.locale }

Once you're sure your page is configured with a locale, then you should add both your javascript locale files and the provided javascripts to your application.js

//= require_tree ./locale
//= require gettext/all

The default function name is window.__, to avoid conflicts with underscore.js. If you want to alias the function to something else in your javascript you should also instruct the javascript and coffeescript parser to look for a different function when finding your translations within the config file config/gettext_i18n_rails_js.yml, these are valid available options:

output_path: "app/assets/javascripts/locale"
handlebars_function: "__"
javascript_function: "__"
jed_options:
  pretty: false

If you prefer an initializer file within your rails application you can use that in favor of the YML configuration as well:

GettextI18nRailsJs.config do |config|
  config.output_path = "app/assets/javascripts/locale"

  config.handlebars_function = "__"
  config.javascript_function = "__"

  config.jed_options = {
    pretty: false
  }
end

Todo

  • More deep testing against multiple Rails versions
  • Extend the current test suite, especially handlebars

Contributing

Fork -> Patch -> Spec -> Push -> Pull Request

Authors

License

MIT

Copyright

Copyright (c) 2012-2015 Dropmysite.com <https://dropmyemail.com>
Copyright (c) 2015 Webhippie <http://www.webhippie.de>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].