create .po file from database table (multilingual, l10n I18n)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

create .po file from database table (multilingual, l10n I18n)

ava-3

Hello,

building multilingual websites is an ongoing process because content
of websites often change.
Therefore translations have to be done for every new release.

Instead of extracting the po files and then translation the file
content I wish to do something smarter.
- keep translations in a db table
- translate only new content
- generate .po file from db table
- keep translation effort to a minimum.


I would still use the console extract and merge the new content in the
db table.

Has anybody done something similar and could provide some examples?

-- Andy



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

euromark (munich)

you should take a look at my ideas a couple of weeks ago
http://www.cakephpforum.net/index.php?showtopic=1588

i am almost finished with this plugin
(as i had the same intention you have - keeping the work at a minimum,
especially with multiple sites to work with)

my ideas go a little bit further
importing/exporting from other .po files or database translation
tables the ones that are equal to the new project's
(same string: usually you can use this translated string right away)
still flagging this field with "not approved"

allowing "non-programmers" to translate via web-interface
(just dump the new table to a .po file afterwards

experimental thoughts:

maybe even allow "rewriting" some strings in the templates themselves
__('someString') could be found similar to the shell extraction method
and replace by __('someNewString') right from the webinterface
if there was a spelling error or whatever
this should be allowed to some people, though (maybe even localhost
only)
the changes could be commited to svn afterwards - and the live site
updated with these changes

mark


On 12 Aug., 13:03, ava <[hidden email]> wrote:

> Hello,
>
> building multilingual websites is an ongoing process because content
> of websites often change.
> Therefore translations have to be done for every new release.
>
> Instead of extracting the po files and then translation the file
> content I wish to do something smarter.
> - keep translations in a db table
> - translate only new content
> - generate .po file from db table
> - keep translation effort to a minimum.
>
> I would still use the console extract and merge the new content in the
> db table.
>
> Has anybody done something similar and could provide some examples?
>
> -- Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

ava-3

Hi Mark,

how can I help (testing, reviewing, developing)?  Can you provide the
code?

Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

euromark (munich)

your gmx address does not seem to work
i tried to contact you but got a delivery failure (not exists)
maybe you want to drop me a line instead

mark

On 15 Aug., 09:23, ava <[hidden email]> wrote:
> Hi Mark,
>
> how can I help (testing, reviewing, developing)?  Can you provide the
> code?
>
> Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

ava-3

Hi Marc,

as for multilingual I suggest the following procedure:

1. create po file by bake  (cake.php i18n extract)
2. load po file into translation table:
   - flag new records as new (status: n)
   - set current date for existing records if msgid matches.

3. translation can now take place in the web application: user
(translator) flags translated records as "translated" (status: t)

4. create a new po file for each language, source is the translation
table.
   - take "not translated" text if the item is not translated.



Translation Table:

CREATE TABLE `translations` (
  `id` int(7) NOT NULL auto_increment,
  `msgid` varchar(100) ,
  `locale` char(2) default 'en',
  created timestamp,
  last_used timestamp,
  status char(1),    -- (t:translated, n: new, needs translation, r:
to be reviewed, u: updated, needs translation
  `msgstr` text ,
);

create unique index on msgid,locale

Housekeeping:
- delete translations that are not used for 18 months.


..text extract from pot file:

#: /views/feedback/add.ctp:44
#: /views/feedback/bytag.ctp:62
#: /views/feedback/main.ctp:101
#: /views/feedback/view.ctp:29
#: /views/person/contact.ctp:22
msgid "your Email"
msgstr ""

On 15 Aug., 12:46, "euromark (munich)" <[hidden email]>
wrote:

> your gmx address does not seem to work
> i tried to contact you but got a delivery failure (not exists)
> maybe you want to drop me a line instead
>
> mark
>
> On 15 Aug., 09:23, ava <[hidden email]> wrote:
>
> > Hi Mark,
>
> > how can I help (testing, reviewing, developing)?  Can you provide the
> > code?
>
> > Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

euromark (munich)

quite similar - but straight forward
i like it :)


On 20 Aug., 21:15, ava <[hidden email]> wrote:

> Hi Marc,
>
> as for multilingual I suggest the following procedure:
>
> 1. create po file by bake  (cake.php i18n extract)
> 2. load po file into translation table:
>    - flag new records as new (status: n)
>    - set current date for existing records if msgid matches.
>
> 3. translation can now take place in the web application: user
> (translator) flags translated records as "translated" (status: t)
>
> 4. create a new po file for each language, source is the translation
> table.
>    - take "not translated" text if the item is not translated.
>
> Translation Table:
>
> CREATE TABLE `translations` (
>   `id` int(7) NOT NULL auto_increment,
>   `msgid` varchar(100) ,
>   `locale` char(2) default 'en',
>   created timestamp,
>   last_used timestamp,
>   status char(1),    -- (t:translated, n: new, needs translation, r:
> to be reviewed, u: updated, needs translation
>   `msgstr` text ,
> );
>
> create unique index on msgid,locale
>
> Housekeeping:
> - delete translations that are not used for 18 months.
>
> ..text extract from pot file:
>
> #: /views/feedback/add.ctp:44
> #: /views/feedback/bytag.ctp:62
> #: /views/feedback/main.ctp:101
> #: /views/feedback/view.ctp:29
> #: /views/person/contact.ctp:22
> msgid "your Email"
> msgstr ""
>
> On 15 Aug., 12:46, "euromark (munich)" <[hidden email]>
> wrote:
>
> > your gmx address does not seem to work
> > i tried to contact you but got a delivery failure (not exists)
> > maybe you want to drop me a line instead
>
> > mark
>
> > On 15 Aug., 09:23, ava <[hidden email]> wrote:
>
> > > Hi Mark,
>
> > > how can I help (testing, reviewing, developing)?  Can you provide the
> > > code?
>
> > > Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

AD7six
In reply to this post by ava-3



On Aug 20, 9:15 pm, ava <[hidden email]> wrote:

> Hi Marc,
>
> as for multilingual I suggest the following procedure:
>
> 1. create po file by bake  (cake.php i18n extract)
> 2. load po file into translation table:
>    - flag new records as new (status: n)
>    - set current date for existing records if msgid matches.
>
> 3. translation can now take place in the web application: user
> (translator) flags translated records as "translated" (status: t)
>
> 4. create a new po file for each language, source is the translation
> table.
>    - take "not translated" text if the item is not translated.
>
> Translation Table:
>
> CREATE TABLE `translations` (
>   `id` int(7) NOT NULL auto_increment,
>   `msgid` varchar(100) ,
>   `locale` char(2) default 'en',
>   created timestamp,
>   last_used timestamp,
>   status char(1),    -- (t:translated, n: new, needs translation, r:
> to be reviewed, u: updated, needs translation
>   `msgstr` text ,
> );

Why don't you just write a model/datasource to edit the po files
directly? Challenging thought it might be, you could even pull the
extract task appart and use the same file writing logic.

AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

ava-3

Here's my prototype: feedback is appreciated!

(Part1):  Model and DDL

<?php
class Translation extends AppModel {
   var $name = 'Translation';
   var $useTable = 'ax_translation';

   function import($filename) {
      // set the filename to read from
      if (empty($filename)) $filename='default.pot';
      $filename = ROOT . DS . 'app' . DS. 'locale' . DS . $filename;
      $filename= '/usr/local/www/41max.com/www/dev/app/locale/
default.pot';

      // open the file
      $filehandle = fopen($filename, "r");
      while (($row = fgets($filehandle)) !== FALSE) {
         if (substr($row,0,7) == 'msgid "') {
            // parse string in hochkomma:
            $msgid = substr($row, 7 ,(strpos($row,'"',6)-8));
            if (!empty($msgid)) {
               $row = fgets($filehandle);
               if (substr($row,0,8) == 'msgstr "') {
                  $msgstr = substr($row, 8 ,(strpos($row,'"',7)-9));
               }
               // check if exists
               $trec = $this->find(array("Translation.msgid" =>
$msgid, "locale"=>"en"));
               if (empty($trec)) {
                  $this->create();
                  $this->data['Translation']['msgid'] = $msgid;
                  $this->data['Translation']['msgstr'] = $msgstr;
                  $this->data['Translation']['locale'] = 'en';
                  $this->data['Translation']['status'] = 'n';
                  $this->save($this->data);
               } else {
                  $this->setLastUsed($trec['Translation']['id']);
               }
            }
         }
      }
      fclose($filehandle);
   }

   function setLastUsed($id) {
      $ret = $this->query("update ax_translation ax set last_used =
current_timestamp where id = " . $id);
      return $ret;
   }
}

?>


/*
CREATE TABLE ax_translation (
    id serial,
    msgid varchar(255) not null ,
    locale char(2) default 'en',
    created timestamp with time zone,
    last_used timestamp with time zone,
    status char(1),    -- (t:translated, n: new, needs translation, r:
to be reviewed, u: updated, needs translation
    msgstr text
);

CREATE UNIQUE INDEX ax_translation_msgid ON ax_translation USING btree
(msgid, locale);

*/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

ava-3


Part 2: Controller

<?php
class TranslationsController extends AppController {
   var $name = 'Translation';
   var $components = array('Axtranslate');
   var $langarr = array
('de'=>'ger','es'=>'spa','el'=>'gre','fr'=>'fre','it'=>'ita','ar'=>'ara','nl'=>'dut','zh'=>'chi');

   function import() {
       // Step 1: import default.pot File
       $this->Translation->import('default.pot');
   }

   function export() {
      // Step 3: export default.po file to the relevant directory
      $filename= 'f' . gmdate('YmdHis');
      foreach ($this->langarr as $k => $v):

         $path = ROOT.DS.'app'.DS.'locale'.DS.$v;
         if (!file_exists($path)) mkdir($path);
         $path .= DS.'LC_MESSAGES';
         if (!file_exists($path)) mkdir($path);
         $file = $path.DS.$filename;
         if (!file_exists($path)) touch($file);

         $file = new File($path.DS.$filename);
         $tmprec = $this->Translation->find('all',
            array('conditions' => array('Translation.locale' => $k)));
         foreach ($tmprec as $rec):
            $file->write('msgid "' .$rec['Translation']
['msgid'] .'"'."\n");
            $file->write('msgstr "'.$rec['Translation']
['msgstr'].'"'."\n");
         endforeach;
         $file->close();

         if (file_exists($path.DS.'default.po'))
             rename ($path.DS.'default.po',
$path.DS.'default.po.old'.gmdate('YmdHis'));
         rename ($path.DS.$filename,$path.DS.'default.po');
      endforeach;
   }

   function trans() {
      // Step 2: translate to all languages defined in $langarr

      $trec = $this->Translation->findAllByLocale('en');
      foreach ($trec as $rec):
         foreach ($this->langarr as $k => $v):
            $tmprec = $this->Translation->find('all',
               array('conditions' => array('Translation.locale' =>
$k,'Translation.msgid'=> $rec['Translation']['msgid'])));
            if (count($tmprec) == 0) {
               $this->data['Translation']['msgstr'] = $this-
>Axtranslate->translate($rec['Translation']['msgid'], 'en', $k);
               $this->data['Translation']['msgid'] = $rec
['Translation']['msgid'];
               $this->data['Translation']['locale'] = $k;
               $this->data['Translation']['status'] = 'm';
               $this->Translation->save($this->data);
            }
         endforeach;

      endforeach;
   }
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

ava-3

Part 3: Axtranslate

<?php
//  copy code from http://code.google.com/p/php-language-api/source/browse/trunk/google.translator.php
class AxtranslateComponent extends Object {

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

ava-3

Summary

the above solution does the following:
- extract msgid and msgstr from file 'default.po'
- automatic translation all messages using google translation (it's a
good starting point anyway)
- export msgid and msgstr to the relevant directories (default.po)

still to to: an edit function to manually edit the translations.

feedback is welcome.

regards,  Andy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

trouet
This post has NOT been accepted by the mailing list yet.
In reply to this post by ava-3
You can try translating your po files using this online localization tool: https://poeditor.com/. It's really efficient and it has a useful API which you can use.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: create .po file from database table (multilingual, l10n I18n)

kaka89
This post has NOT been accepted by the mailing list yet.
In reply to this post by ava-3
hi ava-3! You can send code for me. Source code in url " http://code.google.com/p/php-language-api/source/browse/trunk/google.translator.php " don't have. thank you. have nice weekend!
Loading...