Quoting Chak Man Li (2014-06-04 20:10:20)
> Hello Stats,
> 
> I am investigating L20n and got a question for special cases handling in a
> L20n. I could not find any example to do that even with L20n expressions
> (due to unsupported indexOf function). Could you give me some ideas /
> suggestions?
> 
> 
> 
> *possessive*
> -> "This is {name}'s dog"
> -> "This is {name}' dog", if {name} ends with "s"
> 
> *in French*:
> -> "C'est le chien de {name}", if {name} starts with a consonant, e.g.
> "Babette"
> -> "C'est le chien d'{name}", if {name} starts with a vowel e.g. "Amelie"

Hi Chak,

This is sadly a limitation of L20n at this time.  We have an open 
ticket to address this in the future, but it's not being actively 
worked on.

    https://bugzilla.mozilla.org/show_bug.cgi?id=925189

As a work-around, you could expose the first and the last letter on the 
object that's passed to L20n:

{
  name: {
    value: 'Amelie',
    first: 'A',
    last: 'e'
  }
}

And then in the localization resource a localizer can create a macro 
like this:

English

    <endsWithS($letter) {
      $letter == 's' ?
        'yes' : 'no'
    }>

    <dog[endsWithS($name.last)] {
      yes: "This is {{$name}}' dog",
      no: "This is {{$name}}'s dog"
    }>


French

    <commenceParVoyelle($lettre) {
      $lettre == 'a' ||
      $lettre == 'e' ||
      $lettre == 'i' ||
      $lettre == 'o' ||
      $lettre == 'u' ||
      $lettre == 'y' ?
        'oui' : 'non'
    }>

    <dog[commenceParVoyelle($name.first)] {
      oui: "C'est le chien d'{{$name}}",
      non: "C'est le chien de {{$name}}"
    }>

This allows to keep the separation between the code of the app and its 
localizations.  The logic specific to French lives in the French 
localization resource.

However, this is clearly suboptimal, because other languages might need 
more metadata than just the first and the last letter.  I confess I'm 
not a big fan of this approach.

If you know which languages you want to support, this may however be an 
acceptable solution.

HTH,
-stas

ps.  CC'ing the tools-l10n list which will be interested by this case.



-- 
@stas
_______________________________________________
tools-l10n mailing list
[email protected]
https://lists.mozilla.org/listinfo/tools-l10n

Reply via email to