Merge lp:~jtv/launchpad/recife-findtranslationmessage into lp:~launchpad/launchpad/recife
Status: | Merged |
---|---|
Approved by: | Edwin Grubbs |
Approved revision: | no longer in the source branch. |
Merged at revision: | 9166 |
Proposed branch: | lp:~jtv/launchpad/recife-findtranslationmessage |
Merge into: | lp:~launchpad/launchpad/recife |
Diff against target: | 0 lines |
To merge this branch: | bzr merge lp:~jtv/launchpad/recife-findtranslationmessage |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Edwin Grubbs (community) | code | Approve | |
Review via email: mp+34297@code.launchpad.net |
Commit message
POTMsgSet.
Description of the change
= POTMsgSet.
For the Recife feature branch. This makes a POTMsgSet available in the class interface: findTranslation
There was already a private method of a similar name, but it accepted a dict mapping plural form numbers to POTranslation objects. The desired new interface takes a dict mapping plural form numbers to translation strings. So I implemented the new method as a wrapper around the former.
The conversion from dict-of-strings to dict-of-
I rewrote that code to be slightly more sensible and now it blows up if passed a list. You'll see that in lib/lp/
Finally, I inverted the default divergence policy: if there are matching diverged and shared messages, which one should it prefer? The original internal method preferred the shared one because that suited the present use-case. But in general a diverged message takes precedence over a shared one, so I considered that a more suitable default.
To test,
{{{
./bin/test -vvc -m lp.translations
./bin/test -vvc -m lp.translations
}}}
No lint,
Jeroen
Hi Jeroen,
This is a nice branch. I just have one comment below that we already discussed on IRC.
-Edwin
>=== modified file 'lib/lp/ translations/ model/potmsgset .py' translations/ model/potmsgset .py 2010-08-26 08:51:48 +0000 translations/ model/potmsgset .py 2010-09-01 14:11:25 +0000 TranslationCons tants.MAX_ PLURAL_ FORMS): pluralform] is not None): get(pluralform) pluralform] pluralform] = ( getOrCreateTran slation( translation) ) pluralform] = None nMessage( self, pofile, potranslations, shared= True): Message( self, pofile, translations=None, None, prefer_ shared= False):
>--- lib/lp/
>+++ lib/lp/
>@@ -560,25 +562,39 @@
> potranslations = {}
> # Set all POTranslations we can have (up to MAX_PLURAL_FORMS)
> for pluralform in xrange(
>- if (pluralform in translations and
>- translations[
>+ translation = translations.
>+ if translation is not None:
> # Find or create a POTranslation for the specified text
>- translation = translations[
> potranslations[
> POTranslation.
> else:
> potranslations[
> return potranslations
>
>- def _findTranslatio
>- prefer_
>- """Find a matching message in this `pofile`.
>+ def findTranslation
>+ potranslations=
The potranslations parameter can be removed.
>+ """Find the best matching message in this `pofile`. nslations( translations) ingTranslationM essage( shared= prefer_ shared)
>
> The returned message matches exactly the given `translations`
> strings (except plural forms not supported by `pofile`, which
>- are ignored).
>-
>- :param potranslations: A list of translation strings.
>+ are ignored in the comparison).
>+
>+ :param translations: A dict mapping plural forms to translation
>+ strings.
>+ :param prefer_shared: Whether to prefer a shared match over a
>+ diverged one.
>+ """
>+ potranslations = self._findPOTra
>+ return self._findMatch
>+ pofile, potranslations, prefer_