GetTextã§æ¥æ¬èªåãã¦ã¿ãã
ä»ã¾ã§ãRuby GetTextãå©ç¨ããããã«ã¯ã以ä¸ã®ã¤ã³ã¹ãã¼ã«ä½æ¥ãå¿ è¦ã ã¨æã£ã¦ããã
- RubyGemsã«ããRuby GetTextã®ã¤ã³ã¹ãã¼ã«
- configureã¨makeã«ããGNU GetTextã®ã¤ã³ã¹ãã¼ã«
ã¨ãããããããã調ã¹ã¦ã¿ãã¨ãLocomotiveã§Railsãå©ç¨ãã¦ããç°å¢ã§ã¯ãRuby GetText、GNU GetTextのどちらも、すでにインストールされていたã®ã ãä»ã¾ã§ã®ããã«ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ããã¾ã§ããªããæ¥æ¬èªå*1ããç°å¢ãæ´ã£ã¦ããã¨ã¯...ãæ©éãå©ç¨ããã¦é ããã¨ã«ã
-
-
- ã©ã®ããã«æ¥æ¬èªåãããã確èªããããã«ãActiveHeartãjascaffoldã§æ¥æ¬èªåããåã®ããã¸ã§ã¯ãã«æ»ãã¦è©¦ãã¦ã¿ãã
-
ãã¡ã¤ã«ã®åºæ¬è¨å®
ãã¨ãããã®Ruby on RailsでRuby-GetTextを使うãåèã«ã以ä¸ã®ããã«è¨å®ãããï¼æè¬ã§ãï¼ï¼
config/environment.rbã¸ã®è¿½è¨
- æåã¨æå¾ã«ä»¥ä¸ã®è¿½è¨ãããã
$KCODE = 'u' require 'jcode' ...ï¼éä¸çç¥ï¼... require 'gettext/rails'
app/controllers/application.rbã¸ã®è¿½è¨ã¨åé¤
- ãªã¬ã³ã¸è²ã®è¡ã1è¡è¿½å ããã
- ã³ã¡ã³ã#ã«ããè¡ã¯ãã¹ã¦åé¤ããã*2ï¼#before_filter :set_charsetã#endã¾ã§ãï¼
# Filters added to this controller will be run for all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base init_gettext "softwarebook" #before_filter :set_charset #private #def set_charset # headers['Content-Type'] = "text/html; charset=utf-8" unless request.xhr? #end end
ããã¾ã§è¨å®ãã¦ããµã¼ãã¼ãåèµ·åãã¦ç¢ºèªãã¦ã¿ãã
ããã ãã§ããã§ã«ã¨ã©ã¼è¡¨ç¤ºã¯æ¥æ¬èªåããã¦ããï¼ï¼ã¨ã©ã¼ã®æè¨ããã¡ããã¨ãããã§çµãã£ã¦ããã®ãå¬ãããï¼
ã¾ããã·ã¹ãã ç°å¢è¨å®ã®è¨èªç°å¢ã§ãæåªå
ã®è¨èªãéå½èªã«å¤ãã¦ã¿ãã¨...
ãã®ããã«ãéå½èªã§è¡¨ç¤ºãããããã®æç¹ã§ãã¨ã©ã¼è¡¨ç¤ºã¯å¤è¨èªã«å¯¾å¿ãã¦ããããã ï¼ç´ æ´ãããï¼
lib/tasks/gettext.rakeãã¡ã¤ã«ã®æ°è¦ä½æ
翻訳ãã¡ã¤ã«ãæ½åºãã¦ã翻訳è¾æ¸ã«å¤æããrakeãã¡ã¤ã«ãæºåããã
- RadRailsã§ãlib/tasksãã©ã«ããå³ã¯ãªãã¯ãã¦ãæ°è¦ >> ãã¡ã¤ã«ãé¸æããã¡ã¤ã«åãgettext.rakeã«ãã¦è¿½å ããã
- Ruby on RailsでRuby-GetTextを使うãåèã«ã以ä¸ã®ããã«ãã£ã¦ã¿ãããªã¬ã³ã¸è²ã®é¨åã ãå¤æ´ããã
desc "Update pot/po files." task :updatepo do require 'gettext/utils' GetText.update_pofiles( "softwarebook", #ããã¹ããã¡ã¤ã³å(init_gettextã§ä½¿ç¨ããåå) Dir.glob("{app,config,components,lib}/**/*.{rb,rhtml}"), #ã¿ã¼ã²ããã¨ãªããã¡ã¤ã« "softwarebook 1.0.0") #ã¢ããªã±ã¼ã·ã§ã³ã®ãã¼ã¸ã§ã³ end desc "Create mo-files" task :makemo do require 'gettext/utils' GetText.create_mofiles(true, "po", "locale") end
ãã¹ãéãï¼
Ruby GetTextãGNU GetTextã¨é£æºãã¦ä½¿ãããã«ã¯ãã¿ã¼ããã«ããã³ãã³ãã©ã¤ã³ã§æä½ããã¨ä¸æãåããã
Locomotiveã«ã¤ã³ã¹ãã¼ã«ããã¦ããã½ããã¦ã§ã¢ç¾¤ã¯ã/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin以ä¸ã®æ·±ããã£ã¬ã¯ããªé層ã«ã¤ã³ã¹ãã¼ã«ããã¦ãããã¿ã¼ããã«ããæä½ããå©ä¾¿æ§ãèããã°ãä¸è¨ãã£ã¬ã¯ããªãã³ãã³ããµã¼ããã¹ã«ç»é²ããã¦ããæ¹ã使ãåæãè¯ãã
ã¿ã¼ããã«ãèµ·åãã¦ãPATHå¤æ°ã®å
容ã確èªãã¦ã¿ãã
MacBook:~ zari$ echo $PATH /Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin:/usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
ãªãã¨ããã§ã«ãã¹ã¯éã£ã¦ãããï¼ä»¥åãå¥ã®åé¡ã§è©¦è¡é¯èª¤ã®ä¸ãè¨å®ããã®ã ã¨æããï¼
ãããè¨å®ããã¦ããªãå ´åã¯ã~/.bash_profileã«è¿½è¨ãããpicoã§éãã¦ã¿ãã
MacBook:~ zari$ cd MacBook:~ zari$ pico .bash_profile
èªåã®PATHå¤æ°ã®é¨åã¯ä»¥ä¸ã®ããã«è¨å®ããã¦ãããï¼webãã©ã¦ã¶ã®ç°å¢ã«ãã£ã¦ã¯ãæ¹è¡ãã¦è¡¨ç¤ºããã¦ãã¾ãããå®éã«ã¯1è¡ã§å ¥åãã¦ããï¼
export PATH=/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin:/usr/local/mysql/bin:/usr/local/bin:/usr/local/sbin:$PATH
ä½æ¥ããã¼
大ã¾ããªä½æ¥æé ã¯ã以ä¸ã®ãããªæµãã
- 翻訳ãå¿ è¦ãªæè¨ã_()ã§å²ããä¾ï¼_('Edit')
- .potãã¡ã¤ã«ãä½æãããï¼ããã¸ã§ã¯ããã翻訳対象ã®_(æè¨)ãæ½åºãããã¡ã¤ã«ï¼
- ããã.poãã¡ã¤ã«ã«å¤æãããï¼.potãã¡ã¤ã«ã«ç¿»è¨³æè¨ãå ¥åãããã¡ã¤ã«ï¼
- ããã«.moãã¡ã¤ã«ã«å¤æãããï¼å®è¡æã«GetTextãåç §ãã翻訳è¾æ¸ãã¡ã¤ã«ï¼
æä½æ¥ã¯ã3.ã§ç¿»è¨³æè¨ãå
¥åããé¨åããã以å¤ã¯rakeã³ãã³ããèªåå¦çãã¦ãããã
ã¯ããã¦ã®ç¿»è¨³
ãã®ããã¸ã§ã¯ãã§åãã¦ç¿»è¨³ããæã¾ã§ã¯ãã¡ãã£ã¨ã ãæéãæããããª...ããã¨æã£ã¦ãããã§ããæ£å¸¸ã«æ©è½ããæé ãåãã£ã¦ãã¾ãã°ãå®ã¯ãããªã«æéã§ã¯ãªãã£ãããã®å¾ã®ã¡ã³ããã³ã¹ã®å¿«é©ãããå¤è¨èªã«ã対å¿ã§ãããã¨ãèããã¨ãæ¥æ¬èªåã®ä»çµã¿ã¨ãã¦ãããã§ç解ãããã¨ãåºæ¥ã¦è¯ãã£ãã
ä½æ¥ã¯ä»¥ä¸ã®æé ã ãï¼æ¬å½ã¯äºåã«ããã¥ã¼ãã¢ãã«ã®ç¿»è¨³å¯¾è±¡ã®æè¨ã_()ã§å²ã£ã¦ãããã¹ãã ããå®é¨çã«ä½ãæå®ããªãã§ãã£ã¦ã¿ããï¼
.potãã¡ã¤ã«ã®æ½åº
- ã¿ã¼ããã«ãèµ·åãã¦ãããã¸ã§ã¯ããã©ã«ãã«ç§»åããã
MacBook:~ zari$ cd ~/railsapp/softwarebook2
- ã¿ã¼ããã«ã§ãrake updatepoã³ãã³ããå®è¡ãããï¼こうすればRadRailsで操作してもOKï¼
MacBook:~/railsapp/softwarebook2 zari$ rake updatepo (in /Users/zari/railsapp/softwarebook2) po/softwarebook.pot
- RadRailsã«æ»ã£ã¦ãsoftwarebook2ããã¸ã§ã¯ããå³ã¯ãªãã¯ãã¦ãæ´æ°ãããã¨...
- po/softwarebook.potãã¡ã¤ã«ã¨ãã©ã«ããä½æããã¦ããã
- ä½ã_()ã§å²ã¾ãªãã¦ãããã¼ãã«åã¨ãã£ã¼ã«ãåã¯ç¿»è¨³å¯¾è±¡ã¨ãã¦æ½åºãããã
.poãã¡ã¤ã«ã«å¤æ
- radRailsã§ãä¸è¨poãã©ã«ããå³ã¯ãªãã¯ãã¦ãæ°è¦ >> ãã©ã«ããé¸æããã©ã«ãåjaã§ä½æããã
- ã¿ã¼ããã«ã§ãä¸è¨poãã©ã«ãã«ãã£ã¬ã¯ããªã移åããã
MacBook:~/railsapp/softwarebook2 zari$ cd po
- ã¿ã¼ããã«ã§ãmsginitã³ãã³ãã§.potãã¡ã¤ã«ã.poãã¡ã¤ã«ã«å¤æããã
MacBook:~/railsapp/softwarebook2/po zari$ msginit -i softwarebook.pot -o ja/softwarebook.po
- 以ä¸ã®ãããªã¡ãã»ã¼ã¸ãåºã¦ãã¦ã¼ã¶ã¼ã翻訳ã®ãã£ã¼ãããã¯ãéãã¡ã¼ã«ã¢ãã¬ã¹ãæ±ããããã
The new message catalog should contain your email address, so that users can give you feedback about the translations, and so that maintainers can contact you in case of unexpected technical problems. sed: 8: "{ h s/^[^@]*@\(.*\)$/\1 ...": unterminated substitute pattern Couldn't find out about your email address. Please enter your email address. taro@gmail.com
- ã¡ã¼ã«ã¢ãã¬ã¹ãå ¥åããã¨...
sed: 8: "{ h s/^[^@]*@\(.*\)$/\1 ...": unterminated substitute pattern Retrieving http://www.iro.umontreal.ca/translation/registry.cgi?team=index... done. Please visit your translation team's homepage at http://www.iro.umontreal.ca/translation/HTML/team-ja.html http://www.iro.umontreal.ca/contrib/po/HTML/teams.html http://www.iro.umontreal.ca/contrib/po/HTML/translators.html http://www.iro.umontreal.ca/contrib/po/HTML/index.html and consider joining your translation team's mailing listCreated ja/softwarebook.po.
- ããã«å¦çã¯ç¶ããja/softwarebook.poãã¡ã¤ã«ãä½æãããã
.poãã¡ã¤ã«ã翻訳
- poãã¡ã¤ã«ã®å 容ã¯ã以ä¸ã®ããã«ãªã£ã¦ããã
# Japanese translations for softwarebook package. # Copyright (C) 2006 THE softwarebook'S COPYRIGHT HOLDER # This file is distributed under the same license as the softwarebook package. # zarigani tosh <>, 2006. # msgid "" msgstr "" "Project-Id-Version: softwarebook 2\n" "POT-Creation-Date: 2006-12-14 15:25+0900\n" "PO-Revision-Date: 2006-12-14 15:37+0900\n" "Last-Translator: zarigani tosh <>\n" "Language-Team: Japanese\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" #: app/models/keyword.rb:- msgid "keyword" msgstr "" #: app/models/keyword.rb:- msgid "Keyword|Name" msgstr "" #: app/models/software.rb:- msgid "software" msgstr "" #: app/models/software.rb:- msgid "Software|Title" msgstr "" #: app/models/software.rb:- msgid "Software|Description" msgstr "" #: app/models/software.rb:- msgid "Software|Url" msgstr "" #: app/models/software.rb:- msgid "Software|Created on" msgstr "" #: app/models/software.rb:- msgid "Software|Updated on" msgstr "" #: app/models/software.rb:- msgid "Software|Keyword" msgstr "" #: app/models/software.rb:- msgid "Software|User" msgstr ""
- msgidã«å¯¾ãã翻訳æè¨msgstrã以ä¸ã®ããã«è¨å®ããã
...ï¼éä¸çç¥ï¼... #: app/models/keyword.rb:- msgid "keyword" msgstr "ãã¼ã¯ã¼ã" #: app/models/keyword.rb:- msgid "Keyword|Name" msgstr "ãã¼ã¯ã¼ã" #: app/models/software.rb:- msgid "software" ......ãã¼ãã«åãã¨ã©ã¼è¡¨ç¤ºã®ã¿ã¤ãã«ãªã©ã«è¡¨ç¤ºãããã msgstr "ã½ããã¦ã§ã¢" #: app/models/software.rb:- msgid "Software|Title" ......ãã£ã¼ã«ãåãåã ã®ã¨ã©ã¼ãè¦åãããªã¹ãã®é ç®åã¨ãã¦è¡¨ç¤ºãããã msgstr "ã¿ã¤ãã«" #: app/models/software.rb:- msgid "Software|Description" msgstr "æ¦è¦" #: app/models/software.rb:- msgid "Software|Url" msgstr "URL" #: app/models/software.rb:- msgid "Software|Created on" msgstr "ä½ææ¥æ" #: app/models/software.rb:- msgid "Software|Updated on" msgstr "ä¿®æ£æ¥æ" #: app/models/software.rb:- msgid "Software|Keyword" msgstr "ãã¼ã¯ã¼ã" #: app/models/software.rb:- msgid "Software|User" msgstr "" ......翻訳ããå¿ è¦ãç¡ããã°ãå ¥åããªãã¦ãè¯ãã
.moãã¡ã¤ã«ã«å¤æ
- RadRailsã®ãRakeã¿ã¹ã¯ãã¿ãã§ããã«ãã¦ã³ãªã¹ãããmakemoãé¸æãããï¼ãªããã°ãç´æ¥ãã¼å ¥åãããï¼
- /locale/ja/LC_MESSAGES/softwarebook.moãã¡ã¤ã«ã¨ãã©ã«ããä½æãããã
- ããã¾ã§ãGetTextã®ä½æ¥ã§è¿½å ãããpoãã©ã«ãã¨localeãã©ã«ãã®æ§æã¯ä»¥ä¸ã®ããã«ãªã£ãã
- 以ä¸ã§ãwebãã©ã¦ã¶ã§ç¢ºèªãã¦ã¿ãã¨ããããªæãã§æ¥æ¬èªåããã¦ãããã¨ã©ã¼è¡¨ç¤ºã®ãã¼ãã«åããã£ã¼ã«ãåããæ¥æ¬èªã§è¡¨ç¤ºãããããã«ãªã£ãã
2åç®ä»¥éã¯ãå·®åã ã翻訳
ä¸åº¦ãã¯ããã¦ã®ç¿»è¨³ãã¾ã§ä½æ¥ãé²ãã¦ãã¾ãã°ããã®å¾ã®ã¡ã³ããã³ã¹ä½æ¥ã¯ã¨ã¦ãå¿«é©ã ã_('翻訳æè¨')ã®ããã«å²ã£ããã翻訳ãããæã«ã以ä¸ã®æé ãç¹°ãè¿ãã ãã
æé | ä½æ¥ç°å¢ | ä½æ¥å 容 | ä½æ¥çµæ |
---|---|---|---|
1 | ã¿ã¼ããã« | rake updatepoã³ãã³ããå®è¡ãããï¼こうすればRadRailsで操作してもOKï¼ | .potãã¡ã¤ã«ã¨.poãã¡ã¤ã«ãåæã«å·®åæ´æ°ãããã |
2 | RadRails | .poãã¡ã¤ã«ãéãã¦å¯¾å¿ãã翻訳æè¨ãå·®åã ã追è¨ããã | |
3 | RadRails | ãrakeã¿ã¹ã¯ãã¿ãããmakemoã³ãã³ããå®è¡ããã | .poãã¡ã¤ã«ã.moãã¡ã¤ã«ã«å¤æãããã |
- ã¿ã¼ããã«ã§ã¯ä¸ã«ã¼ã½ã«ãã¼ã§ãã³ãã³ãå±¥æ´ãå¼ã³åºããã®ã§ããã¼å ¥åã®æéã¯ä¸è¦ã ã
- ã¿ã¼ããã«ã§.potãã¡ã¤ã«ã.poãã¡ã¤ã«ãæ´æ°ãããã¨ãRadRailsã§åèªã¿è¾¼ã¿ããæ*3ã«ãå¤æ´ããã¼ããã¾ããï¼ãã¨ç¢ºèªãã¦ãããå¿ ããã¯ãããé¸æããã
- ããç¬èªã«Railsãã¤ã³ã¹ãã¼ã«ãã¦ãã¦ãGNU GetTextãã¤ã³ã¹ãã¼ã«ããã¦ããªãã¨ãæé 1ã®rake updatepoã§ã.poãã¡ã¤ã«ãå·®åæ´æ°ãããªããããã¯ã¨ã¦ãä¸ä¾¿ãªãã¨ãªã®ã§ãå¿
ãGNU GetTextãã¤ã³ã¹ãã¼ã«ããã¹ãã ãï¼Locomotiveç°å¢ãªãã¤ã³ã¹ãã¼ã«æ¸ã ãï¼GNU GetTextç¡ãã§ã¯ããã®ãã¨ç¿»è¨³æè¨ãå¢ãã¦ããã¨ãããæ°ããªããªã...ã
-
- GNU GetTextãã¤ã³ã¹ãã¼ã«ããã¦ããªãå ´åãç°å¢å¤æ°MSGMERGE_PATHにrmsgmergeコマンドのパスを指定するã¨ããæ¹æ³ãããããã ã以ä¸ã®ããã«ã³ãã³ãå ¥åããã
-
MacBook:~/railsapp/softwarebook2 zari$ rake updatepo MSGMERGE_PATH=rmsgmerge
-
-
- RadRailsã®Rakeã¿ã¹ã¯ããrake updatepoãå®è¡ããã¨ãèªåã®ç°å¢ã§ã¯ä»¥ä¸ã®ãããªã¨ã©ã¼ã«ãªã£ã¦ãã¾ã...ããã¾ãã«.potãã¡ã¤ã«ã¨.poãã¡ã¤ã«ã®å 容ãã¯ãªã¢ããã¦ãã¾ã...ã
- ãmsgmergeã¨ããã³ãã³ããè¦ã¤ãããªããã¨è¦åããã¦ãã¦ã ãã®å¯¾è±¡ã¯/Applications/Locomotive2/.../ruby.rbãã¡ã¤ã«ã®96è¡ç®ãããããããããRadRailsã«msgmergeã³ãã³ãã®ãã¹ãæãã¦ãããã°è¯ãã®ã ã¨æãã®ã ãããã®å¯¾å¦ã®ä»æ¹ã¯ä¸æ...ãæ®å¿µã
-
(in /Users/zari/railsapp/softwarebook2)
po/softwarebook.pot
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/gettext-1.8.0/lib/gettext/parser/ruby.rb:96: command not found: msgmerge po/softwarebook.pot tmp.pot
po/ja/softwarebook.po
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/gettext-1.8.0/lib/gettext/parser/ruby.rb:96: command not found: msgmerge po/ja/softwarebook.po tmp.pot
-
-
- ä¸è¨ã®ã¨ã©ã¼ã®è§£æ±ºçãè¦ã¤ãã£ããRadRailsã®ãRakeã¿ã¹ã¯ãã¿ãã§ãã«ãã¦ã³ã¡ãã¥ã¼ããupdatepoãé¸æãã¦ãå³å´ã®é ç®ã«MSGMERGE_PATH=/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin/msgmergeã¨å ¥åãã¦å®è¡ããã°ãRadRailsã§ãæ£å¸¸ã«æ©è½ãããï¼さらに、解決策が見つかった!ï¼
-
*1:GetTextã¯æ¥æ¬èªåã ãã«çã¾ãããæ§ã ãªè¨èªã«å¯¾å¿ãããã¨ãåºæ¥ããã¤ã¾ããå½éåãå®ç¾ãããµãã¼ãããã¦ãããã
*2:Ruby GetTextå é¨ã§åçã®å¦çããã¦ããã¦ããã®ã§ä¸è¦ã
*3:RadRails以å¤ã§ããã¡ã¤ã«ããã©ã«ãæ§æãå¤æ´ããå ´åã¯ã対象ã®ãã¡ã¤ã«ãããã«ã¯ãªãã¯ããããä¸ä½ã®ãã©ã«ãã§å³ã¯ãªãã¯ãã¦ãæ´æ°ããé¸æããã¨ããã®å¤æ´ãåæ ãããã