[ruby-gnome2-doc-cvs] [Hiki] update - tips_libglade_i18n

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2004年 4月 27日 (火) 23:46:06 JST


-------------------------
REMOTE_ADDR = 80.137.231.65
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/de/?tips_libglade_i18n
-------------------------
  =Internationalisation (i18n) in Ruby/libglade unterst$B(Bzen
  
  ==Einf$B(Brung
  Dieses Tutorial zeigt, wie man auch mit Ruby/libglade die Vorteile von per Gettext $B(Bersetzten Strings nutzen kann. F$B(B diejenigen, die mit dem Konzept von Gettext nicht vertraut sind, empfiehlt sich die Lekt$B(Be des ((<Handbuches|URL:http://www.gnu.org/software/gettext/manual>)).
  
  Bevor es losgeht, stellen Sie bitte sicher, das Ruby-GNOME2 auf ihrem Rechner installiert ist.
  
  Der urspr$B(Bgliche Autor dieses Hilfetextes benutzte Ruby 1.8.1, Ruby-GNOME2 0.8.1 und gettext 0.12.1 auf einem Gentoo-Linux-Rechner. Falls etwas bei Ihnen nicht funktioniert wie hier beschrieben, dann denken Sie daran, dass dies durch Versionsunterschiede verursacht sein k$B(Bnte. Keines der Beispiele wurde unter MS Windows getestet; es w$BgS(Be nat$B(Blich hilfreich, wenn jemand dem Autor diesbez$B(Bliche Informationen zugehen lassen k$B(Bnte.
  
  Viele der folgenden Informationen stammen aus der ((<PyGTK FAQ|URL:http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq22.001.htp>)).
  
  ==Das Interface in Glade erstellen
  Der erste Schritt ist die Erstellung der Benutzeroberfl$BgD(Bhe mithilfe von glade-2. Beachten Sie, dass jedes Widget mit einem Textfeld in der XML-Datei das translatable-Attribut mit dem Wert "yes" besitzt.
  
  W$BgI(Blen Sie nun unter Projekt -> Einstellungen -> LibGlade-Einstellungen "$B\b(Bersetzbare Zeichenketten speichern".
  Als Dateinamen geben Sie z.B. glade-msg.c an. Der Output wird ein C-$Bdh(Bnliches Format besitzen, das von xgettext verwendet wird.
  
- == Creating the translations
+ == Die $B\b(Bersetzungen erstellen
  
- ((*Note*)) this section is heavily borrowed from the ((<PyGTK FAQ|URL:http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq22.001.htp>)).
- mentioned above. I included this section so the reader doesn't have to jump around.
+ ((*Note*)) Dieser Abschnitt ist stark an die ((<PyGTK FAQ|URL:http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq22.001.htp>)) angelehnt. Er wurde hier eingebunden, damit die Leser nicht zwischen verschiedenen Seiten herumspringen m$B|s(Bsen.
  
- Next you'll want to create the main translation file. To do this, use the following
- command:
+ Als n$Bdc(Bhstes werden Sie vermutlich die f$B|r(B die $B\b(Bersetzung verwendete Hauptdatei erstellen wollen. Um das zu tun, k$Bvn(Bnen Sie den folgenden Befehl auf der Shell eingeben:
  
    xgettext -kN_ -o myapp.pot glade-msg.c
  
- Look inside of this file. You should see the glade strings listed. 
+ Werfen Sie einen Blick in diese Datei. Wenn alles richtig funktioniert hat, m$B|s(Bsten Sie dort die Glade-Strings aufgelistet sehen k$Bvn(Bnen.
  
- This .pot file should be sent to the translators. Once they get the file, they should
- create a .po file. As an example, to create a German translation they would use:
+ Diese .pot-Datei wird an die $B\b(Bersetzer gesendet. Wenn sie einmal die Datei empfangen haben, sollten Sie eine .po-Datei erstellen. Als Beispiel wird folgender Befehl genutzt, um eine deutsche $B\b(Bersetzung zu erstellen:
  
    LANG=de_DE msginit
  
- This will create de.po, where the translated strings should be entered. The translation
- file needs to be converted to a binary format before use:
+ Dadurch wird de.po erstellt, wo die $B|b(Bersetzten Strings eingetragen werden sollten. Die $B\b(Bersetzungsdatei muss in ein Bin$Bdr(Bformat umgewandelt werden, bevor sie verwendet werden kann:
  
    msgfmt de.po -o myapp.mo
  
- This file should then be placed in the appropriate directory. On my machine,
- this would go in /usr/share/locale/de/LC_MESSAGES/
+ Diese Datei sollte dann in dem entsprechenden Verzeichnis abgelegt werden. In der Umgebung des Autors ist dieses Verzeichnis /usr/share/locale/de/LC_MESSAGES/.
  
- == Writing your code
+ == Code schreiben
  
- Now to tell Ruby/Libglade to load the locale files. Normally you would have a line
- in your code similar to this:
+ Jetzt k$Bvn(Bnen Sie Ruby/Libglade veranlassen, die Dateien zu laden. Normalerweise werden Sie in Ihrem Code eine Zeile haben, die der folgenden $Bdh(Bnelt:
  
    @glade = GladeXML.new('myapp.glade') { |handler| method(handler) }
  
- To get the translated strings to load, you need to specify a locale name to glade so
- it knows which file to load the strings from. Change the above code to:
+ Um die $B|b(Bersetzten Strings zu laden, m$B|s(Bsen Sie einen Locale-Namen f$B|r(B Glade festlegen, damit Glade wei aus welcher Datei die Strings geladen werden sollen. $BDn(Bdern Sie die oben stehenden Code folgenderma$B_e(Bn ab:
  
    @glade = GladeXML.new('myapp.glade', nil, 'myapp') { |handler| method(handler) }
  
- The third parameter, 'myapp', will tell glade to look for 'myapp.mo'. Now to load the
- application:
+ Der dritte Parameter, 'myapp', teilt Glade mit, dass nach der Datei 'myapp.mo' gesucht werden soll. Jetzt laden Sie die Anwendung:
  
    LANG=de_DE ruby myapp.rb
  
- The translated strings should appear. That's all there is to it.
+ Die $B|b(Bersetzten Strings sollten erscheinen. Das ist bis zu diesem Punkt erst einmal alles.
  
  == Auto-generating the binary translation file
  
  ((*Note*)) this section is based on code included with Masao Mutoh's ((<ruby-gettext
  distribution|URL:http://ponx.s5.xrea.com/hiki/ruby-gettext.html>)).
  
  For every translation file, you'll need to create a new .mo file. With Minero
  Aoki's ((<install.rb|URL:http://i.loveruby.net/en/setup.html>)) this becomes very easy
  to automate. 
  
  For this example we will pretend we have German and Spanish translations already
  created, named de.po and es.po, respectively.
  
    cd $PROJECTROOT
    mkdir po
    mkdir po/de
    mkdir po/es
    cp de.po po/de/myapp.po
    cp es.po po/es/myapp.po
  
  Then, in your main directory, create a file named post-setup.rb which contains:
  
    require 'fileutils'
  
    podir = srcdir_root + "/po/"
    modir = srcdir_root + "/data/locale/%s/LC_MESSAGES/"
  
    Dir.glob("po/*/*.po") do |file|
        lang, basename = /po\/([\w\.]*)\/(.*)\.po/.match(file).to_a[1,2]
        FileUtils.mkdir_p modir % lang
        system("msgfmt #{podir}#{lang}/#{basename}.po -o #{modir}#{basename}.mo" % lang)
    end
  
  You may also want to create the following pre-clean.rb:
    
    Dir.glob("data/**/*.mo").each do |file|
        File.delete(file)
    end
  
  Now, when 'ruby install.rb setup' is run, the translation files will be generated.
  On 'ruby install.rb install' they will be installed to the correct place.
  
  == Conclusion
  
  I hope this all was decently clear. If people run into problems, feel free to
  contact me and I will try to help out. I would like to improve this document,
  so also contact me with corrections, etc.
  
  == Author
  
  Zachary P. Landau (kapheine AT hypa DOT net).
  
  The reader should be warned that I am far from an expert on the subject. I only
  very recently started trying to add internationalization support to one of my
  projects. While searching for information, I found only bits and pieces that
  had to be put together. I wrote this tutorial in attempt to keep other people
  from having to do the same.
  
  That being said, I'd be very happy to incorporate additions and corrections from
  people who know more about the subject. Please contact me with any information
  you have.
  
  == ChangeLog
  
  :2004-03-20 Zachary P. Landau
   Initial release





ruby-gnome2-cvs メーリングリストの案内
Back to archive index