I18n of java script

30
i18n of JavaScript Junichi Shinohara @ HDE

description

angular-gettextの紹介です。

Transcript of I18n of java script

Page 1: I18n of java script

i18n of JavaScriptJunichi Shinohara @ HDE

Page 2: I18n of java script

Agenda

・What's i18n?・How to support i18n in Server Side・How to support i18n in Client Side・Introduce AngularJS・Introduce angular-gettext

Page 3: I18n of java script

What’s i18n?

Page 4: I18n of java script

What’s i18n

・i18n = Internationalization・One system supports multiple languages

Page 5: I18n of java script

How to Support i18nin Server Side

Page 6: I18n of java script

How to Support i18n in Server Side

・Server Side = Python, PHP, Erlang and etc.・GNU gettext generally is used

Page 7: I18n of java script

How to use gettext

1. Modify source code2. Extract texts from source code(.pot)3. Translate texts(.po)4. Convert translated texts into binary translated texts(.mo)5. Load binary translated texts on server

Page 8: I18n of java script

・Use template engine like Mako・Use _ method of gettext.py

How to use gettext1. Modify Source Code

Page 9: I18n of java script

How to use gettext2. Extract Texts from Source Code(.pot)

・Create .pot file with pybabel or xgettext

Page 10: I18n of java script

How to use gettext3. Translate Texts(.po)

・Create .po file from .pot file with msgmerge

・Edit .po file with vim or Poedit

Page 11: I18n of java script

How to use gettext4. Convert Translated Texts into Binary Translated Texts(.mo)

・Create .mo file with msgfmt

Page 12: I18n of java script

・Load .mo file on Tornado of Python

How to use gettext5. Load Binary Translated Texts on Server

Page 13: I18n of java script

・Separate translating from developing ・Translators edit po files ・Developers edit source codes・Useful PO file editor like Poedit

 

Good Points of gettext

Page 14: I18n of java script

How to Support i18nin Client Side

Page 15: I18n of java script

How to support i18n in Client Side

・Client Side = JavaScript・GNU gettext Generally is NOT used

Page 16: I18n of java script

How to support i18n in Client Sidewith jQuery UI or jQuery Globalize

・Use GNU gettext Object or JSON・We have to set texts into HTML

Page 17: I18n of java script

How to support i18n in Client Sidewith Server’s Template

・Use GNU gettext・But, JavaScript depends on Server Framework

Page 18: I18n of java script

IntroduceAngularJS

Page 19: I18n of java script

What’s AngularJS?

・JavaScript MVC Framework in Client Side・Developed by Google・Home Page: https://angularjs.org/・Examples: http://www.angularjshub.com/examples/

Page 20: I18n of java script

What’s AngularJS?Concepts of AngularJS

・2 Way Data Binding ・Change Value in Model = Change Value in View $(‘#hoge’).value(‘fuga’)

・Model ・Resource like REST API with $http, $q, and $resource ・Factory like Session Storage or Local Storage・Directive / Filter / Template ・Behaviour as HTML <div ng-model=”items” ng-repeat=”item in items | lowercase”><a>{{item}}</div>

・Controller ・Scope in HTML <div ng-controller=”abcCtrl”></div><div ng-controller=”xyzCtrl”></div>

・Router ・Ajax Frendly URL with $router or angular-ui plugin http://www.example.com/blog/#/page/1

 ・pushState / popState with HTML5 Mode

Page 21: I18n of java script

Introduceangular-gettext

Page 22: I18n of java script

What’s angular-gettext?

・Support gettext on AngularJS・Extract text from AngularJS codes・Convert .po file into JSON or Object・Home Page: http://angular-gettext.rocketeer.be/・Examples: https://github.com/rubenv/angular-gettext-example

Page 23: I18n of java script

How to use angular-gettext

1. Modify source code2. Extract texts from source code(.pot)3. Translate texts(.po)4. Convert translated texts into JSON(.json)5. Load JSON on AngularJS or Server

Page 24: I18n of java script

・Use translate directive on View

・Use gettext function on Controller

How to use angular-gettext1. Modify Source Code

Page 25: I18n of java script

How to use angular-gettext2. Extract Texts from Source Code(.pot)

・Create .pot file with Grunt and grunt-angular-gettext

・We can merge other .pot file which is created by pybael with msguniq

Page 26: I18n of java script

How to use angular-gettext3. Translate Texts(.po)

・Create .po file from .pot file with msgmerge

・Edit .po file with vim or Poedit

Page 27: I18n of java script

How to use angular-gettext4. Convert translated texts into JSON(.json)

・Create .json file with Grunt and grunt-angular-gettext

Page 28: I18n of java script

・Load JSON on AngularJS

How to use angular-gettext5. Load JSON on AngularJS

Page 29: I18n of java script

・translate directive ・We do NOT have to set translated texts into HTML ・JavaScript does NOT depend on Server Framework・gettext ・Use a de fact standard ・Use the same as .po file of server side・Translated texts is JSON format ・3rd party tool like jQuery Globalize use the JSON

Good Points of angular-gettext

Page 30: I18n of java script

Thank you for your attention!