Topic: How to translate words from the database

Some parts of the program get the words from the database itself, and they are all in English.
Like each, hrs,  Payment due within 10 days and so on.
Is there a way to translate these words? I have tried to  put _() around the items in the sql query, but it does not seem to work

Re: How to translate words from the database

Data belonging to a database should be in your natural language.

Simply translate them inside FrontAccounting.

The chart of Accounts script should have been translated from the beginning.

Joe

Re: How to translate words from the database

These data should also be "internationalized". If people working in the same company from different countries are using the program, these data should also be in the language of the user. A user in Germany sending out an invoice should have the messages in German, a user in Norway in Norwegian.
As it is now there is only one choice.
To fix this you need to introduce a country table and add the different translations to the appropriate tables so that these messages can be written in the language of the user.

Re: How to translate words from the database

Well if the company is 'internationalized' they will probably use the English language, right?

At least this is my experience.

/Joe

Re: How to translate words from the database

All the user interface is subject to translation, so FA user sending out an invoice in Germany can have messages in German.  The document printout language is defined on target basis (e.g. for invoices you can set document language per customer branch). But unfortunatelly FA does not support multi-language texts stored in database, so e.g. item names will not not be translated.
Janusz

Re: How to translate words from the database

Translatable Text comes from language *.mo files compiled from the translated empty.po files named according to your language.

The Wiki pages for Language and Translation String updation would be useful.

Re: How to translate words from the database

Yes, and then the phrase "Payment due within 10 days" taken from the database would appear in the PO file as

msgid "Payment due within 10 days"
msgstr "whatever it is in your language"

and whenever this phrase appeared in the combo boxes it would be translated to your language.

So my question is: Is there a way to fix this?

Re: How to translate words from the database

All the strings in database are user defined, so we cannot add them to *.po/*.mo file, just because we don't know what is content of your database. You can do it  yourself if you have enough time for it:
1. add the strings from your database tables you want to be translated to all *.po language files you like;
2. translate them and generate *.mo files;
3. find all places in sources where the strings are displayed not translated, and add _() calls over respective variable/expression.

As you see recipe is simple, but you need to spent a couple of days to be satisfied.

Janusz

Re: How to translate words from the database

Some places are easy to find and some are difficult to find.
The Account Types page is an example.
On the screen 2 of the combo boxes can easily be translated as you say, but the 2 others are difficult to find.

The 2 easy ones are found in the "while" statement starting around line 133 in the file /frontaccounting/gl/manage/gl_account_types.php.
In the label_cell function calls around line 150 the _() are inserted as shown below. When the correct translations are inserted in the PO file, they are translated correctly.
I found that the ($parent_text) could not be empty. You have to assign it some value. Otherwise it returns the whole PO file.

while ($myrow = db_fetch($result))
{

    alt_table_row_color($k);

    $bs_text = get_account_class_name($myrow["class_id"]);
    $parent_text = "-";
    if ($myrow["parent"] == '-1')
    {
        $parent_text = "-";
    }
    else
    {
        $parent_text = get_account_type_name($myrow["parent"]) . " ";
    }

    label_cell($myrow["id"]);
    label_cell(_($myrow["name"]));//   here the _() is put
    label_cell(_($parent_text));//   here the _() is put
    label_cell(_($bs_text));//   here the _() is put
    inactive_control_cell($myrow["id"], $myrow["inactive"], 'chart_types', 'id');
    edit_button_cell("Edit".$myrow["id"], _("Edit"));
    delete_button_cell("Delete".$myrow["id"], _("Delete"));
    end_row();
}
--------------------------------------------------------------------------------------------------------------------------------------------
The 2 combo boxes at the bottom of the page are more difficult to handle. I have not managed to find out where to introduce the _(). I have tried several places in the "gl_account_types.php" file and in the ui_lists.php file and the gl_db_account_types.inc file but I cannot find out where to put them.

Do you have any suggestions where to put the _()?

10 (edited by apmuthu 01/29/2013 02:02:55 am)

Re: How to translate words from the database

Do not, in general, use php $ variables inside the translation text directly.

Check the 3166/3167 Mercurial for sprintf for example workarounds. Otherwise the litteral varable name will be parsed instead. Make sure every possible variable value has a translation in the .po/.mo files.

The lines (they seem okay in hindsight):

    label_cell(_($myrow["name"]));//   here the _() is put
    label_cell(_($parent_text));//   here the _() is put
    label_cell(_($bs_text));//   here the _() is put

should possibly be (%d for numbers and %s for strings) where every possible value of :

    label_cell(sprintf(_("%s"), $myrow["name"]));//   here the _() is put
    label_cell(sprintf(_("%s"), $parent_text));//   here the _() is put
    label_cell(sprintf(_("%s"), $bs_text));//   here the _() is put

Even this may not work as intended since %s will be parsed as is and there is no preceeding or succeeding text to be translated. An eval() may have to be done on a cocatenated string containing the variable.

Try the following as well:

    label_cell(_(sprintf("%s", $myrow["name"])));//   here the _() is put
    label_cell(_(sprintf("%s", $parent_text)));//   here the _() is put
    label_cell(_(sprintf("%s", $bs_text)));//   here the _() is put

Maybe a check to see if $parent_text is empty before translation would be all that is needed:

    label_cell($empty(trim($parent_text)) ? "" : _($parent_text));//   here the _() is put

Re: How to translate words from the database

Placed content in Wiki

Re: How to translate words from the database

I finally managed to locate where to put the _() for the combo boxes to get translated.       
It is in the file frontaccounting/includes/ui/ui_lists.inc    around line 190.
The variable $contact_row[1] contains the expression taken from the database that you want to translate.
All you need to do is to add the middle line shown below.

        $value = $contact_row[0];
    $contact_row[1] = _($contact_row[1]);   //   this line is added
    $descr = $opts['format']==null ?  $contact_row[1] :

Then when you manually put the translations in the PO file and make a new MO file your combo boxes will also be translated.

Example:

The first 2 entries in the chart_types table are "Current Assets" and "Inventory Assets".

Then add the following to your PO file:

#: from table chart_types
msgid "Current Assets"
msgstr "Omløpsmidler"

#: from table chart_types
msgid "Inventory Assets"
msgstr "Anleggsmidler"

The translation shown above is Norwegian, but you put the translation in your own language.

I have made a file of most of the database entries that should be translated and will try to make it available for all to download.