HOWTO: Translating GnuCash
Last update: 2003-07-04

The concept of this document is to give you step-by-step instructions on 
how to update (or create if non-existent) language translations for the 
gnucash project.  

Any additions or corrections to this file should be sent to either Jon 
Lapham <lapham@extracta.com.br>, Christain Stimming <stimming@tuhh.de>, 
or directly to the gnucash-devel mailing list.

Sections:
1) Mailing lists, IRC and web sites
2) Get the source
3) Contact the maintainer of your language
4) Building, Installing and running GnuCash
5) The glossary file
6) Initial processing of the translation file
7) Translating the .po file
8) Testing and submitting your translations
9) Problems
10) How to translate the GnuCash guide and/or help files
11) How to translate the files containing the new account hierarchies

==============================================================================
1) Mailing lists, IRC and web sites

Translators will probably find 3 gnucash mailing lists of interest.  General
use questions and answers are found on the gnucash-users mailing list, 
specific development questions go to the gnucash-devel list and your finished
translation file are sent to the gnucash-devel list.

To subscribe or view archives of these lists, go the the gnucash web site, 
and follow the links to the mailing lists:
https://lists.gnucash.org/mailman/listinfo

Another excellent place to get help is on IRC, as many of the developers hang 
out there and are eager to help.  Go to the #gnucash channel at 
"irc.gnome.org".  If you don't know what that mean, fire up an IRC client 
(for example, xchat), connect to irc.gnome.org and then type "/join 
#gnucash".

The main gnucash web site is loaded with information:
https://www.gnucash.org/

The GNU Translation Project is another way to submit translations:
https://translationproject.org/html/welcome.html

==============================================================================
2) Get the source

The first thing to do is to download the latest STABLE branch of gnucash.
This could be easily done by visiting
https://www.gnucash.org/pub/gnucash/sources/stable/
and grab the latest stable source package.

Please do not use the HEAD branch from SVN, since the text in the HEAD branch 
changes so much, it would be a waste of time to translate it.  Do not worry, 
when the HEAD branch becomes stable, the existing translations in the STABLE 
branch will be merged.  Your work will not be lost.

==============================================================================
3) Contact the maintainer of your language

To find out who is the last person to work on your language, look near the 
top of the po/XXXX.po file which corresponds to your language.   If your 
language does not have a .po file available, you can build one my issuing 
this command:

FIXME: command to build a new .po file

The beginning of your .po file should look something similar to this:

# Localization for Portuguese-Brazil
# Copyright (C) 2003 Free Software Foundation, Inc.
# Jon Lapham <lapham@extracta.com.br>, 2003
# Jose Carlos Nascimento - <joseca@psabs.com>, 2001.
# 
msgid ""
msgstr ""
"Project-Id-Version: GnuCash 2.0.0\n"
"POT-Creation-Date: 2003-05-16 16:42-0300\n"
"PO-Revision-Date: 2003-06-02 12:00-0300\n"
"Last-Translator: Jon Lapham <lapham@extracta.com.br>\n"
"Language-Team: NONE \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"

Look to see who the "Last-translator" was, and send an email to that person 
and ask what you can do to help.  This is important because if there already 
is an active maintainer of the translation file, you should interact directly
with him or her.  If there is not Last-translator, or that person is not 
maintaining the file actively (and tells you to take over), you will become 
the maintainer and you should change the "Last-translator" to your name and 
email address.

==============================================================================
4) Building, Installing and running GnuCash

Before starting to work on your translations, it is suggested that you 
build the gnucash source code.  This way you can get your system set up 
correctly with all the development packages you need.  It is a good idea
to actually run gnucash with your new translations because it is quite 
helpful to see the phrases in the context of the running program.

For how to build and install, please refer to ../README

After installation, insure that it works by running (as a normal user,
no need to be root here):

$ /usr/local/bin/gnucash

It is a good idea to use absolute paths like this to insure you run 
the proper gnucash executable.  To run your OS pre-installed version of
gnucash, usually you can type:

$ /usr/bin/gnucash

Unless on some special systems, e.g. FreeBSD, where the OS installed
version sits in /usr/local/bin/, in which case you need OS-specific knowledge.

In either case, you can easily switch between the various languages the 
gnucash has available by setting the LANG env var before the call to the
executable. In sh-like shell environment this could be done by:

$ LANG=pt_BR /usr/local/bin/gnucash

(other shell like tcsh may behave differently, please to refer to related
manuals)

==============================================================================
5) The glossary file

Inside the po/glossary/ directory should be a "glossary" file for your 
language.  This file contains a bunch of commonly used terms found in gnucash.
It is recommended that you get this file translated first, and use it as a 
guide when translating the real .po file.  

Go into the glossary directory and rebuild your language's glossary file:

cd po/glossary/
./txt-to-pot.sh gnc-glossary.txt > gnc-glossary.pot

If your .po glossary file does not exist, use this gnc-glossary.pot file to
create it:

cp gnc-glossary.pot XXXX.po

If your .po glossary file does exist, use the msgmerge program to update it:

/usr/bin/msgmerge -o XXXX.po XXXX.po gnc-glossary.pot

Now, open your language's glossary file and translate it completely.

==============================================================================
6) Initial processing of the translation file

Before you begin actual translation work, you should update the gnucash.pot 
file and use this to update your .po file.  This process will insure that 
you have the latest translatable strings.

cd po/
rm gnucash.pot
make gnucash.pot

If your language file does not exist, use the gnucash.pot file as a template
for it:

cp gnucash.pot XXXX.po

If your language file does exist, update it using the msgmerge program:

/usr/bin/msgmerge -o XXXX.po XXXX.po gnucash.pot

The top of the .po file should be edited somewhat.  The comments at the 
top of the file should be changed to be current:

# Messages in Deutsch f�r GnuCash
# Copyright (C) 1999 Free Software Foundation, Inc.
# Jan-Uwe Finck <Jan-Uwe.Finck@bigfoot.de>, 1999.

Make sure that the header of your .po file contains this line:
"Plural-Forms: nplurals=2; plural=n != 1;\n"

...and that you change the "Last-translator" string to your name.

==============================================================================
7) Translating the .po files

Finally.  You are ready to do some translating!

There are many translation editors, KBabel, for example, works well for 
GnuCash.  Some Editors are noted here:
https://translationproject.org/html/software.html

If you are familiar with a text editor, e.g. vim or emacs, you can also 
manually edit the .po files.  Here is an example of translating some text 
into German:

Before:
#: messages-i18n.c:11
msgid ""
"The GnuCash personal finance manager.\n"
"The GNU way to manage your money!"
msgstr ""

After, the translation in the de.po file:

#: messages-i18n.c:11
msgid ""
"The GnuCash personal finance manager.\n"
"The GNU way to manage your money!"
msgstr ""
"GnuCash: Ihr pers�nlicher Finanzmanager.\n"
"Der GNU-Weg, ihr Geld zu verwalten !"

You should read through every translation in the .po file at least once.  
If you translate a string that has the phrase "#, fuzzy" in the comments
above it, remove the word fuzzy.   A fuzzy translation means that the 
computer guessed what the translation should be. If you use a translation
editor, the "fuzzy" translation are marked in different ways in different 
translation editor, please refer to their documents for how to work with them.

After you finish translating, you should not have any "#, fuzzy" strings left.

For example:

#: messages-i18n.c:35
#, fuzzy, c-format
msgid ""
"There was an error writing the file\n"
"     %s\n"
"\n"
"%s"
msgstr ""
"Es gab einen Fehler beim �ffnen der Datei. \n"
"     %s."

You need to correct the translated string and remove the 'fuzzy' keyword.
For example:

#: messages-i18n.c:35
#, c-format
msgid ""
"There was an error writing the file\n"
"     %s\n"
"\n"
"%s"
msgstr ""
"Es gab einen Fehler beim �ffnen der Datei. \n"
"     %s."

Notice that the comment "c-format" was not removed.  That is correct, you 
should leave that.

When you see the comment "c-format", it means that the format codes in the 
translatable string are referring to C formatting codes.  So, '%s' means text, 
'%d' means an integer, etc...

==============================================================================
8) Testing and submitting your translations

You must check that your new translations are programmatically correct (ie: 
that there are no unclosed quotes, etc).  To do this, use the msgfmt program

/usr/bin/msgfmt -c --statistics XXXX.po

This will report any errors in your .po file if it finds them.

If you want to see your translations within a running version of gnucash,
simply place your .po file in your SVN copy of the gnucash source code (which
you have previously installed) and from within the po/ directory type (you
may need to be root to do this):

make install

Now you can run gnucash with your new translations:

$ LANG=XXXX /usr/local/bin/gnucash

When you are happy with the new translation file, email a gzipped version
of it to the gnucash-devel mailing list.

gzip XXXX.po
(email this file using your favorite mail client)

Note that on this list we would kindly ask to send patches as attachments, not 
within email text.

If you know how to make a patch, a patch is also welcome. Patches are more 
helpful if there are more than one people working on one translation file.

==============================================================================
9) Problems

If you see any "Gtk-CRITICAL" messages while running gnucash, it is probably
because you translated a string differently than how it exists in some other
gnome library. You must discover which string you translated differently, and
change the translation to exactly match that of the gnome libraries.

To do this, you need to run gnucash under gdb:

LANG=XXXX /usr/local/bin/gnucash-env gdb /usr/bin/guile

Then, from within gdb, issue:
run -e main -s /usr/local/libexec/gnucash/overrides/gnucash --g-fatal-warnings

Eventually, gnucash should crash (because of the --g-fatal-warnings 
directive), when it does, issue from within gdb:

backtrace

You should see some output that looks like this:

#0  0xffffe002 in ?? ()
#1  0x42028a73 in abort () from /lib/tls/libc.so.6
#2  0x4019d3d8 in g_logv () from /usr/lib/libglib-1.2.so.0
#3  0x4019d414 in g_log () from /usr/lib/libglib-1.2.so.0
#4  0x40500fdd in gtk_type_check_object_cast () from 
/usr/lib/libgtk-1.2.so.0
#5  0x407292e5 in gnc_mdi_tweak_menus (mc=0x825adb0) at gnc-mdi-utils.c:574
#6  0x40729d13 in gnc_mdi_child_changed_cb (mdi=0x8266fd8, prev_child=0x0,
     data=0x8265fd8) at gnc-mdi-utils.c:861

Notice position #5 which has "gnc_mdi_tweak_menus at 
gnc-mdi-utils.c:574"?  Open that source file and find line 574:

573:  widget = gnc_mdi_child_find_menu_item(mc, "_View/_Toolbar");
574:  gtk_signal_handler_block_by_data(GTK_OBJECT(widget), info);

So, the problem is with the translation of "_View/_Toolbar".  The "/" is a 
menu separator, so you now know that the problem is with either the 
translation of "_View" or "_Toolbar".  By switching to an English gnucash
and looking through your .po file, you should be able to find the problem.
Change the offending translation to whatever you see in the gnucash app.
Remember that the translations must contain the proper underscores.

------------
To follow gnucash as it access files, 
strace /usr/local/bin/gnucash

==============================================================================
10) How to translate the GnuCash guide and/or help files

This section describes the actions needed to translate the manual.

First, you must *have* the gnucash-doc package installed:

1) Checkout the documentation
cvs -z3 -d :pserver:cvs@cvs.gnucash.org:/home/cvs/cvsroot checkout \
	gnucash-docs
  FIXME: change the cvs command to svn here
2) Create a new directory (if it doesn't already exist) in guide/<locale> 
   where <locale> is something like es, en_GB, or pt_PT.
3) Copy the files from guide/C into this directory.
4) Recreate the image files in guide/C/figures so that they are
   appropriate to the locale.
5) Edit all the xml files and translate for the locale.
6) Test that your xml file has no syntax errors
   xmllint --valid --noout gnucash-guide.xml

To translate the help files, repeat steps 2-5 but replace the "guide"
directory with "help".

==============================================================================
11) How to translate the files containing the new account hierarchies

This section describes the actions needed to translate the files
containing the new account hierarchies.

1) Create a new directory accounts/<locale>.
2) Copy the acctchrt_* files from accounts/C to accounts/<locale>
3) Do not change any xml tags.
For each file:
4) Change the gnc-act:title, gnc-act:short-description, and
   gnc-act:long-description to contain appropriately translated text.
   Do not add any newlines in the long description except at the end
   and beginning of the string.
5) For each gnc:account in the file translate the act:name, and
   act:description fields.  Please do not translate any other fields.

Note: You absolutely don't need to translate all of the files from
accounts/C.  A subset of those are fine as well. Probably several of
them will not apply to your local legislative/economic system anyway.
For a really customized account hierarchy you might better create a
new account hierarchy file in GnuCash, and then, by hand-editing the
xml code, split it up into several files and cut&paste the appropriate
tags from the accounts/C/acctchrt_* files.

----------------------------------------------------------------------

Thanks so very much to all the translators for their hard effort and
excellent work.
