翻蚳è
ããïŒããã¯ã ãã«ãœããããžã§ã¯ãã«é¢ä¿ãããMozilla IdentityããŒã ã«ããNode.jsã·ãªãŒãºã® 10çªç®ã®èšäºã§ãã
ãµã€ã¯ã«ã®ãã¹ãŠã®èšäºïŒ
Node.jsã¢ããªã±ãŒã·ã§ã³ã®ããŒã«ã©ã€ãºã«é¢ãã以åã®èšäºã§ã¯ãã³ãŒãã§i18n-abideã¢ãžã¥ãŒã«ã䜿çšããæ¹æ³ãåŠã³ãŸããã ããã°ã©ããŒãšããŠã®ç§ãã¡ã®ä»äºã¯ãå®éã«ã¯ãã³ãã¬ãŒãã§è¡ãã©ãããã
gettext()
åŒã³åºãã§ã¢ããªã±ãŒã·ã§ã³ã³ãŒããã©ãããããšããäºå®ã§çµãããŸããã ããããã¢ããªã±ãŒã·ã§ã³ã®ããŒã«ã©ã€ãºãšç¿»èš³ã®äœæ¥ã¯ãŸã å§ãŸã£ãã°ããã§ãã
ããŒã«ããã
Mozilla PersonaããŒã ã®ããŒã«ã©ã€ãºããŒã«ãããã¯ãä»ã®Mozillaã³ãã¥ããã£ã§äœ¿çšãããŠããããŒã«ãšäºææ§ããããŸãããNodeã«åºæã®èŠªãã¿ããããšæè»æ§ã®å©ç¹ãä¿æããŠããŸãã
Mozillaãããžã§ã¯ãã¯ã»ãŒ15幎åã§ãããããŒã«ã©ã€ã¶ãŒãšç¿»èš³è
ã®ããŒã ã¯ãªãŒãã³ãœãŒã¹ã®äžçã§æ倧ã®ïŒãããŠã¯ãŒã«ãªïŒããŒã ã®1ã€ã§ãã ãã®ãããå€ããŠãããããªããŒã«ãšãã£ãŠãããã»ã©ã銎æã¿ã®ãããã®ãé·ãéåºã䜿çšããŠããŸãã
Gettext
GNU Gettextã¯ããã¹ã¯ãããããã³Webã¢ããªã±ãŒã·ã§ã³ãããŒã«ã©ã€ãºããããã«èšèšãããããŒã«ãããã§ãã Nodeã®ã³ãŒããšãã³ãã¬ãŒããæžããšãã¯ãã©ãã§ãè±èªã®ãã¬ãŒãºã䜿çšããŸãããããããã
gettext()
åŒã³åºãã§ã©ããããŸãã
gettextã¯2ã€ã®ããšãè¡ããŸãã
- ã¢ã»ã³ããªäžã«ãã¢ããªã±ãŒã·ã§ã³ã§æ€åºããããã¹ãŠã®è¡ã®ãã£ã¬ã¯ããªãã³ã³ãã€ã«ããŸãã
- å®è¡æã«ããããããŒã«ã©ã€ãºããããªãã·ã§ã³ã«çœ®ãæããŸãã
æœåºããããã¹ãŠã®è¡ã¯ãæ¡åŒµåã
.po
ããã¹ããã¡ã€ã«ã«ä¿åãããŸããå°æ¥ãããããpoãã¡ã€ã«ãšåŒã³ãŸãã
Poãã¡ã€ã«
Poãã¡ã€ã«ã¯ãgettextãèªã¿åããæžã蟌ã¿ãããã³çµåã§ããç¹å®ã®åœ¢åŒã®ããã¹ããã¡ã€ã«ã§ãã
zhTW / LCMESSAGES / messages.po poãã¡ã€ã«ã®å
容ã®äŸã次ã«ç€ºããŸãã
åŸã§è©³ããæ€èšããŸãããããã§
msgid
ã¯è±èªã®æååã§ããã
msgstr
ã¯äžåœèªãžã®ç¿»èš³ã§ããããšãç解ããããšãéèŠã§ãã
#
ã§å§ãŸããã®ã¯ãã¹ãŠã³ã¡ã³ãã§ãã ãã®äŸã®ã³ã¡ã³ãã¯ãã³ãŒãå
ã®ãã®è¡ã®å Žæã瀺ããŠããŸãã
Gettextã¯ãæååãšpoãã¡ã€ã«ãæäœããããã®å€ãã®ä»ã®ããŒã«ãæäŸããŸãã ç§ãã¡ããããã«è§ŠããŸãã
ãªããã®ããŒã«ããããªã®ã
gettextã䜿çšããããã®Node.jsã¢ãžã¥ãŒã«ã®è©³çŽ°ãªèª¿æ»ã«å
¥ãåã«ããªããã®ç¹å®ã®ããŒã«ã»ãããéžæããã®ããèªåããå¿
èŠããããŸããïŒ
1幎åãåœéåãšããŒã«ãªãŒãŒã·ã§ã³ã®ããã®æ¢åã®Node.jsã¢ãžã¥ãŒã«ã詳现ã«èª¿ã¹ãŸããã ãããã®ã»ãšãã©ã¯ãæååãä¿åããããã®ç¬èªã®èªè»¢è»ãšJSONããŒã¹ã®ãã©ãŒããããçºæããŸããã
äžæ¹ãMozillaã¯
POEdit ã
Verbatim ã
Translate Toolkitã Pootleãªã©ã®ããŒã«ãé·ã䜿çšããŠããŸããã 人ã
ã«ååŠç¿ã匷ãã代ããã«ã䜿ãæ
£ããæšæºãããã»ã¹ãšäºææ§ã®ããããŒã«ãéçºããããšã«ããŸããã
Poãã¡ã€ã«ã¯ã翻蚳è
ã®äº€æãšååã®ããã®äžè¬çãªåœ¢åŒã§ãã 翻蚳ã®ããã«ç§ãã¡ããè¡ãåãåããå®æããããã¹ããæäŸããã®ã¯ãã®åœ¢åŒã§ãã
Mozillaã§PHPãšPythonã«æ»ã£ãŠå€ãã®éçºçµéšãããã®ã§ãGettextã¯éåžžã«äŸ¿å©ã§ãã Webã¢ããªã±ãŒã·ã§ã³ãæé·ããããå€ãã®ããã¹ããå«ãŸããã«ã€ããŠãååã«ãã¹ããããããŒã«ãšGettext APIã®äœ¿çšãå¿
èŠãšãããã¥ã¢ã³ã¹ããŸããŸãçŸããŸãã
翻蚳è
çšã®poãã¡ã€ã«ãäœæããŸã
ãã®ãããã³ãŒããgettextåŒã³åºãã§ããŒã¯ã¢ããããŸããã 次ã¯ïŒ ãã¹ããªã³ã°ãã©ã€ããŒããšåŒã°ãããã®ãå®è¡ãããŸãã ããªãèªèº«ã翻蚳è
ããŸãã¯ç®¡çè
ã«ãªããŸãã æååãã©ã€ããŒã¯äœãããŸããïŒ
- ã¢ããªã±ãŒã·ã§ã³ã«æåã«çŸããè¡ãååŸããŸãã
- åŸç¶ã®ãªãªãŒã¹ã§ãå€æŽãããæ°ããè¡ãæ€çŽ¢ããããåé€ãããè¡ãããŒã¯ããŸãã
- 翻蚳è
ã®ããŒã ããšã«poãã¡ã€ã«ãæºåããŸãã
- 競åã解決ããå€æŽãŸãã¯åé€ããã翻蚳æååãããŒã¯ããŸãã
ããã¯å°ããããã«ãããããããŸãããã幞ããªããšã«ããããã®ã¿ã¹ã¯ã®ã»ãšãã©ã¯èªååãããŠããŸãã åé¡ãçºçããå Žåã«ã®ã¿ãã©ã€ã³ãã³ãä»å
¥ããå¿
èŠããããŸãã
msginitãxgettextãmsgfmtãããã³ãã®ä»ã®
GNU GettextããŒã«ã¯ãè¡ãã£ã¬ã¯ããªãæäœããããã®åŒ·åãªã»ããã§ãã ãããã®ããŒã«ã§ã¯ãæååã³ãŒãã®ã¿ãæ©èœããŸãã ã»ãšãã©ã®éçºè
ã¯ããããã«æ°ä»ããªããŸãŸã§ããããšãã§ããŸãã
ãã±ãŒã«ã®ãã¡ã€ã«ããªãŒãäœæããŸãã
$ mkdir -p locale/templates/LC_MESSAGES
ãã®ãã£ã¬ã¯ããªã«ã¯ãpoãã¡ã€ã«ãã³ãã¬ãŒã
.pot
ãã¡ã€ã«ãæ ŒçŽãããŸãã ãããã¯å°æ¥gettextã§äœ¿çšãããŸãã
è¡ã®ååŸ
ååã®èšäºã§ã¯ãi18n-abideãã€ã³ã¹ããŒã«ããŸããã
$ npm install i18n-abide
ä»ã®ã³ãã³ãã©ã€ã³ããŒã«ã®äžã§ããabideã¯æœåºããããæäŸããŸãã ãã®ã³ãã³ãã¯ããã±ãŒã«ãã£ã¬ã¯ããªå
ã®æååãååŸããããã«äœ¿çšãããŸãã
mkdir -p locale/templates/LC_MESSAGES $ ./node_modules/.bin/extract-pot --locale locale
ã¹ã¯ãªããã¯ãã¢ããªã±ãŒã·ã§ã³ã®ãœãŒã¹ã³ãŒãå
šäœã調ã¹ãè¡ãèŠã€ããŠpoãã³ãã¬ãŒããã¡ã€ã«ã«æžã蟌ã¿ãŸãã
åŸæ¥ã®gettextãŠãŒãã£ãªãã£ã䜿çšããŠpotãã¡ã€ã«ãäœæã§ããŸããã䟿å©ã§ã¯ãã¹ãã©ãããã©ãŒã ãªç¹å¥ãªjsxgettextã¢ãžã¥ãŒã«ãäœæããŸããã ããŒãã®äžã§ãextract-potã¯ããã䜿çšããŸãã
Jsxgettextã¯ãã³ãŒãå
ã§
gettext()
åŒã³åºããæ€çŽ¢ãããããããæåååŒæ°ãæœåºããŠãããgettextããŒã«ããããšäºææ§ã®ãã圢åŒã§æååããã©ãŒãããããŸãã ãã®ãããªããããã¡ã€ã«ããã®æç²ã次ã«ç€ºããŸãã
åŸã§ã翻蚳ä»ãã®poãã¡ã€ã«ããã®ãã³ãã¬ãŒãã«åºã¥ããŠäœæãããŸãã 次ã®ããã«ãªããŸãã
ãããã¯ã®æ觊ãè¯ãããããã«ãäžåœèªçšã®
poãã¡ã€ã«ã®å®å
šçãã芧ãã ãã ã
ãã±ãŒã«äœæ
Gettextã»ããã®msginitã³ãã³ãã䜿çšããŠããã³ãã¬ãŒããã¡ã€ã«ã«åºã¥ããŠç¹å®ã®ãã±ãŒã«ã®poãã¡ã€ã«ãäœæããŸãã
$ for l in en_US de es; do mkdir -p locale/${l}/LC_MESSAGES/ msginit --input=./locale/templates/LC_MESSAGES/messages.pot \ --output-file=./locale/${l}/LC_MESSAGES/messages.po \ -l ${l} done
ã¢ã¡ãªã«è±èªããã€ãèªãã¹ãã€ã³èªçšã®poãã¡ã€ã«ãäœæããŸããã
Poãã¡ã€ã«
ããã§ãè¡ãæœåºãããã±ãŒã«ãã©ã«ããŒãäœæããŸããã ããããã¡ã€ã«ããªãŒã®å€èŠ³ã§ãã
locale/ el/ LC_MESSAGES/ messages.po en_US LC_MESSAGES/ messages.po es LC_MESSAGES/ messages.po templates LC_MESSAGES/ messages.pot
ã¢ããªã±ãŒã·ã§ã³ã®ãããã®éšåã«ã¯ã翻蚳è
ãžã®ã¢ã¯ã»ã¹æš©ãä»äžã§ããŸãã ããšãã°ãã¹ãã€ã³ã®ããŒã ã¯
locale/es/LC_MESSAGES/messages.po
ã¢ã¯ã»ã¹ã§ã
locale/es/LC_MESSAGES/messages.po
ã éåžžã«å€§èŠæš¡ãªãããžã§ã¯ããããå Žåã¯ãã¹ãã€ã³èªçãšã¢ã«ãŒã³ãã³èªçã®ã¹ãã€ã³èªçšã«ães-ESãšes-ARã®2ã€ã®åå¥ã®ãã±ãŒã«ãååšããããšããããŸãã
æéãçµã€ã«ã€ããŠãæ°ãããã±ãŒã«ãè¿œå ãããå¯èœæ§ããããŸãã
è¡ã®å€æŽãããŒãž
ãªãªãŒã¹ããšã«æ°ããè¡ãè¿œå ããå€ãè¡ãå€æŽããã³åé€ããŸãã ãããã®å€æŽã«å¿ããŠããã¹ãŠã®poãã¡ã€ã«ãæŽæ°ããå¿
èŠããããŸãã Gettextã«ã¯ããã®ããã®åŒ·åãªããŒã«ããããŸãã ç§ãã¡èªèº«ã®ããã«ãGNU Gettextããã±ãŒãžã®msgmergeã³ãã³ãã䜿çšããmerge-po.shã¹ã¯ãªããã©ãããŒãäœæããŸããã
i18n-abideããŒã«ãã·ã¹ãã ãã¹ã«è¿œå ããŸãã
$ export PATH=$PATH:node_modules/i18n-abide/bin
è¡ã®ããŒãžããã»ã¹ãéå§ããŸãã
$ ./node_modules/.bin/extract-pot --locale locale . $ merge_po.sh ./locale
åããŠãšåæ§ã«ãextract-potã¯ãã¹ãŠã®è¡ãåéãããã³ãã¬ãŒããäœæããŸãã 次ã«ãmerge-po.shã¯ãã¹ãŠã®poãã¡ã€ã«ãæŽæ°ããããããçŸåšã®ããŒãžã§ã³ã®ã¢ããªã±ãŒã·ã§ã³ã«åãããŸãã ãã®åŸã翻蚳ããŒã ãåã³ä»äºãåŒãåããããšãã§ããŸãã
Gettext vs. Invented Not Hereçå矀
gettextã®ä»£ããã«ç¬èªã®JSONããŒã¹ã®ãã€ã¯ãçºæããããšã¯å€§ããããšã§ã¯ãããŸããã Nodeã¢ãžã¥ãŒã«ã®ã»ãšãã©ã®äœæè
ã¯ããã®ãã¹ãéžæããŠããŸãã ããããã¢ããªã±ãŒã·ã§ã³ãæé·ããæ°ããèšèªãè¿œå ããããšãå°ããªåé¡ãéªã ããŸåŒã®ããã«æé·ããŸãã ããšãã°ãmerge-po.shããªãå Žåãé
ããæ©ãããç¬èªã®ããŒãžããŒã«ãäœæããŠãããã°ããå¿
èŠããããŸãã 30åã®ãã±ãŒã«ã®30åã®ãã¡ã€ã«ããçŽå€±ãããæ··ä¹±ããããããããšãªããæåã§æŽæ°ããŸããããã§ãæ··ä¹±ã§ãã
ãŸããgettextã«ã¯å¿
èŠãªãã®ããã¹ãŠæã£ãŠãããããæéãšç¥çµã倧å¹
ã«ç¯çŽãããŸãã
ãããã«
poãã¡ã€ã«ãäœæããã³æŽæ°ããæ¹æ³ãããããããã£ãã®ã§ã翻蚳è
ã®æ³šæã«å§ä»»ã§ããŸãã äžè¬ã«ãåžžã«äºåã«è©±ãåãããã€è»¢éãéå§ã§ããããã©ã®ããªã¥ãŒã ãäºæ³ããããããã€å®äºããããšãæãŸãããã«ã€ããŠè©±ãåãããšããå§ãããŸãã gettextã®ããã¥ã¡ã³ããå匷ããã®ã«ã圹ç«ã¡ãŸãã
ãããã£ãŠãè¡ã¯ç¿»èš³ãããŠããŸãã次ã®èšäºã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã®å®è¡äžã«ããŒã«ã©ã€ãºãã©ã®ããã«æ©èœããããåŠç¿ããŸãã
ãµã€ã¯ã«ã®ãã¹ãŠã®èšäºïŒ