Skip to content

Instantly share code, notes, and snippets.

@jtomasek
Created March 18, 2013 17:49
Show Gist options
  • Save jtomasek/5189239 to your computer and use it in GitHub Desktop.
Save jtomasek/5189239 to your computer and use it in GitHub Desktop.
Javascript translations
Javascript translations:
base requirement:
- have no hardcoded strings in javascript
general aproach:
- have strings defined in view file (html/erb/haml...) in data attribute, this enables their translation
- access these translated strings from javascript
angular directive approach:
- we need to translate strings used in directive templates
- to enable translation, template has to be erb/haml and it has to be served by rails to actually perform the translation
solution: create directive_templates_controller that will serve the directive templates, and define the routes for it.
then in directive definition, load the template eg. templateUrl: "directive_templates/tooltip". This will feed the directive
with correct translated template.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment