-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WIP]: Allow Drupal to use Translate component #4249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -18,6 +18,8 @@ | |||
*/ | |||
class PoFileLoader extends ArrayLoader implements LoaderInterface | |||
{ | |||
private $_header; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_
should be removed.
You need to follow Symfony2 CS, also you should squash your commits (all those merge's should not exist in PR). |
@stloyd : tnx I did no stash as I'm not sure whether all code is ok. Cherrypicking is now possible. And never did git stash. Do you have a good workflow guide for stashing? |
Note that this does not have the legacy of the Drupal history (GPL) that the previous one at #4235 had. |
@@ -38,9 +40,47 @@ public function load($resource, $locale, $domain = 'messages') | |||
return $catalogue; | |||
} | |||
|
|||
public function setHeader($header) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the curly brace should be on its own line for methods and classes. See http://symfony.com/doc/current/contributing/code/standards.html
@clemens-tolboom I think this: http://www.silverwareconsulting.com/index.cfm/2010/6/6/Using-Git-Rebase-to-Squash-Commits is quite good one. Also you can read what we have in Symfony2 docs: http://symfony.com/doc/current/contributing/code/patches.html#rework-your-patch |
I followed along the squash guide @stloyd advised. Tnx for the pointers. I added a new class Gettext as both Po Loader/Dumper and probably Mo Loader/Dumper can use that too. The Gettext Header is now placed into the messages under It can be deleted from the message when using a catalog to load. I'm not sure how to clean it from the Translation messages. So feedback is welcome on that. |
I added Header support for both PoFileLoader and PoFileDumper by introducing a Gettext class. Two tests are marked as Skipped as both indexed as interval messages have issues related to the loaded versus the dumped plural form messages. I fixed PoFileLoader which did a interval instead of a indexed message plural handling. But when loading and next dumping PO files:
So I'm not sure Drupal can use the current version. @goba can tell more about that. Who can test the current version with some real datasets? I continue working on Drupal : Let Symfony Translation component handle language messages |
@clemens-tolboom What do you mean by this? |
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
msgid "One sheep" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loading this translation gives two entries into our internal $messages.
array(
'One sheep' => 'un mouton',
'@count sheeps' => 'un mouton|@count moutons'
);
But the PoFileDumper should merge these back into one Gettext item. I fixed this in my latest push partly as the solution taken is searching for 'un mouton' then replace that while dumping into a single unit with its plural form. See PoFileDumper::extractSingulars.
But what if $messages contains two (2) translation entries with 'un mouton'? We cannot merge those can we?
I hope I documented that code good enough.
The dumping of an Interval is done into a singular form. I'm not sure whether that is parsed back correctly. That is first dump then load it again. So that needs a test. Is it ok to always skip PoFileDumperTest::testDumpFullInterval? |
I've closed the other (GPL troubled version) #4235 |
} else { | ||
$standardRules[] = $part; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are moved to a static method MessageSelector::getRules() for PoFileDumper to use.
Sorry for the noise ... not sure how to handle that FileDumper fix. (I need it for Drupal) Any pointers in how to handle several branches and squash between them? |
See also pull request Fixed PoFileLoader pluralhandling from interval to index. |
See also pull request Fixed for allowing empty translation. |
@stof thanks for the code review. @fabpot thanks for the 3 PR merges. I'm not satisfied from a Symfony point of view with the current PR solution concerning Metadata as It probably works for Drupal but we now have two 'metadata' items Drupal uses Gettext both for application translation bundles as well as a Gettext editor through ie http://localize.drupal.org/translate/languages/fr I think Drupal can make use of ie the PhpFileDumper or other file types easy to I think we should extends MessageCatalogue with a metadata interface allowing for at least Gettext header data items like translation team but ie Gettext comments relating message id's to source code lines could be added as I'm interested to code for that that but the related Drupal issue http://drupal.org/node/1570346 should take all my spare time first :) It would be great to have the current PR committed for Drupal ;) |
@clemens-tolboom - yes, I am also not very sure about this - I am not sure it is a good long term solution - the PR might suit Drupal's needs but that is addressing the issue the wrong way round IMO. Symfony needs to do this the right way and applications should have to adapt themselves to fit. |
@Drak I did not meant Drupal. This works for Gettext oriented (Po|Mo)File* stuff. So I guess we both agree Symfony needs a way handle to Message related MetaData? Can you give us more examples? |
I reworked PoFileDumper as it did not do a decent job. The plural merge was based on translation instead of the source. I fixed that by adding an extra source ID consisting of both the Gettext msgid and msg_plural. This way the reconstruction works way better. TODO: revert the dependency on MessageSelector. |
* @return array | ||
* Ordered list of Gettext keys | ||
*/ | ||
static public function headerKeys() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this should be just public static class variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP Fatal error: Arrays are not allowed in class constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not as constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable != constant =) static public $headerKeys = array();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example of that?
Added empty translation to support translate process. Improved Header management. Fixed CS issues reported by @stof and added some documention. Reworked Plural merge for PoFileDumper. Applied stloyd's CS feedback. Applied CS with php php-cs-fixer.phar fix src/Symfony/Component/Translation/
@clemens-tolboom - is there any chance you can email me? email is in my profile. |
@Drak have you done some cherry picking in the meantime? |
This PR was merged into the master branch. Commits ------- 320fb6c [Translation] changed the MetadataAwareInterface method signatures 11ff433 [Translation] fixed CS in unit tests c40db35 [Translation] removed some code that is not done anywhere else in Symfony 63719a0 [Translation] created a new interface to avoid breaking BC 23e9e65 [Translation] fixed name 5607732 [Translation] added Metadata to MessageCatalogue Discussion ---------- [MessageCatalogue] Add Metadata to MessageCatalogue rework of symfony#4399 For improving the Gettext tools (PO, MO File Loader/Dumper) we need at least storage for their meta data. This patch allows for issues below to store and process ie Po Header, Po Header Pluralisation rule. Open - [[WIP]: Allow Drupal to use Translate component](symfony#4249) - [[2.1][Translator] Symfony translation process & gettext](symfony#4245) Closed: - [[Translation] Po/MoFileLoader parse plurization rules](symfony#3023) It has 1 TODO regarding addCatalogue: it now just override old values with new.
…#4336) Commits ------- 4c4d889 Fixed PoFileLoader pluralhandling from interval to index. Discussion ---------- [BUG] PoFileLoader pluralhandling uses interval instead of index. PoFileLoaders parsed Gettext messages as interval but should have used indexed. I added index only message strings to MessageSelectorTest to reflect this. (this is part of symfony#4249) --------------------------------------------------------------------------- by travisbot at 2012-05-19T10:11:09Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1373653) (merged 4c4d889 into 58b9245).
…ony#4337) Commits ------- dd60166 Fixed for allowing empty translation. Discussion ---------- Fixed for allowing empty translation. PoFileLoader should accept empty translations. PoFileLoader calls array_filter just before returning the $messages thus filtering empty translations. For Drupal we need to be able to load and then translate incomplete PO and POT files. (this is part of [[WIP]: Allow Drupal to use Translate component](symfony#4249)) --------------------------------------------------------------------------- by travisbot at 2012-05-19T11:14:39Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1373933) (merged 5ee0b1e6 into 58b9245). --------------------------------------------------------------------------- by travisbot at 2012-05-19T12:09:48Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374129) (merged dd60166 into 58b9245).
…ony#4339) Commits ------- fb6cf3e Allow for missing whitelines. Discussion ---------- Allow for missing whitelines. The Gettext specification allows for 'whitespace is optional' between message string. For this to work PoFileLoader needs to save found messages on more places while processing. Thus a new method is introduced. For the tests to work PoFileDumper was changed slightly to only emit white-lines when necessary. I added more documentation from the GNU gettext documentation to make the code more understandable. When [[BUG] PoFileLoader pluralhandling uses interval instead of index.](symfony#4336) this patch needs some small rework. (this is part of [[WIP]: Allow Drupal to use Translate component)](symfony#4249) --------------------------------------------------------------------------- by travisbot at 2012-05-19T12:44:19Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374295) (merged fb6cf3e into 58b9245). --------------------------------------------------------------------------- by stof at 2012-05-19T13:19:29Z you need to rebase your branch. github tells us it cannot be merged automatically
Commits ------- 3462afc Tests for PluralizationRules. Discussion ---------- [WIP][Translations][tests] Tests for PluralizationRules. Currently we have no tests PluralizationRules. This patch is an initial one to show we have not enough langcodes in PluralizationRules. I hope this gets in so others can fix the missing langcodes. I'm waiting for [RFC [MessageCatalogue*] Add Metadata to MessageCatalogue](symfony#4399) to get in to continue working on the [[WIP]: Allow Drupal to use Translate component](symfony#4249). --------------------------------------------------------------------------- by travisbot at 2012-05-25T14:38:37Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1433558) (merged 3462afc into 023dbf8). --------------------------------------------------------------------------- by drak at 2012-07-01T09:47:05Z Is there anything pending in this PR?
Commits ------- dd60166 Fixed for allowing empty translation. Discussion ---------- Fixed for allowing empty translation. PoFileLoader should accept empty translations. PoFileLoader calls array_filter just before returning the $messages thus filtering empty translations. For Drupal we need to be able to load and then translate incomplete PO and POT files. (this is part of [[WIP]: Allow Drupal to use Translate component](symfony/symfony#4249)) --------------------------------------------------------------------------- by travisbot at 2012-05-19T11:14:39Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1373933) (merged 5ee0b1e6 into 58b92453). --------------------------------------------------------------------------- by travisbot at 2012-05-19T12:09:48Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374129) (merged dd601662 into 58b92453).
Commits ------- fb6cf3e Allow for missing whitelines. Discussion ---------- Allow for missing whitelines. The Gettext specification allows for 'whitespace is optional' between message string. For this to work PoFileLoader needs to save found messages on more places while processing. Thus a new method is introduced. For the tests to work PoFileDumper was changed slightly to only emit white-lines when necessary. I added more documentation from the GNU gettext documentation to make the code more understandable. When [[BUG] PoFileLoader pluralhandling uses interval instead of index.](symfony/symfony#4336) this patch needs some small rework. (this is part of [[WIP]: Allow Drupal to use Translate component)](symfony/symfony#4249) --------------------------------------------------------------------------- by travisbot at 2012-05-19T12:44:19Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1374295) (merged fb6cf3ef into 58b92453). --------------------------------------------------------------------------- by stof at 2012-05-19T13:19:29Z you need to rebase your branch. github tells us it cannot be merged automatically
Commits ------- 3462afc Tests for PluralizationRules. Discussion ---------- [WIP][Translations][tests] Tests for PluralizationRules. Currently we have no tests PluralizationRules. This patch is an initial one to show we have not enough langcodes in PluralizationRules. I hope this gets in so others can fix the missing langcodes. I'm waiting for [RFC [MessageCatalogue*] Add Metadata to MessageCatalogue](symfony/symfony#4399) to get in to continue working on the [[WIP]: Allow Drupal to use Translate component](symfony/symfony#4249). --------------------------------------------------------------------------- by travisbot at 2012-05-25T14:38:37Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1433558) (merged 3462afc0 into 023dbf80). --------------------------------------------------------------------------- by drak at 2012-07-01T09:47:05Z Is there anything pending in this PR?
This WIP will be followed by smaller PRs as that will speedup the commit progress.
(PRs done: #4336 #4337 #4339)
This patch (still) provide for:
A Gettext class which allow for header and context support. Each PO file may have a header and can contain different msgctxt or domains. To load all domains we need to know the domains available.
PoFileLoader and PoFileDumper can use a Gettext header. The header is loaded into
PoFileLoader loads the Gettext msgctxt values into
To load all domains the default domain must be loaded first then each context can loaded. This can be accomplished by:
MessageSelector is refactored to give PoFileDumper access to it's rules selection. This way PoFileDumper can decide how to dump a given message.
PoFileDumper merges plural messages back into one.
As Gettext specification does not support Interval rules so these are dumped in Gettext singular form by PoFileDumper.
Open issues:
__HEADER__
and__CONTEXT__
are injected into the message array.