L20n/Features/Default values

From MozillaWiki
< L20n‎ | Features
Jump to: navigation, search


goal

enable one of the values in hash or array to be used by default if no index is given or if the index doesn't resolve to any of the existing keys (with some error handling)

examples

<brandName {
  nom: "Firefox",
  gen: "Firefoksa",
  dat: "Firefoksowi",
  loc: "Firefoksie"
}>

In the above example, you can see a simplified example of a brandName entity for the Polish language where we decline the value. Without being able to specify the default value of the hash, the localizer either has to provide an index (which does not make sense for a generic entity like this one), or specify the exact case with each call, like this:

<about "Witaj w {{ brandName.loc }}">

That makes sense, as we know the case here, but it would be beneficial if we could just call the entity without knowing the particular case and get the basic form (in this example - nominative case).

Proposed syntax:

<brandName {
 *nom: "Firefox",
  gen: "Firefoksa",
  dat: "Firefoksowi",
  loc: "Firefoksie"
}>

Now if we reference brandName without any particular index, it will be resolved using the default key "nom".

This change combined with the way L20n resolves errors like missing hash keys allows for a pretty sweet concepts like gender matching for popular names with fallback to a gender neutral form:

/* most popular names */
<_nameList {
  Anna: 'female',
  Patrick: 'male',
  Maradona: 'male'
}>

<likes[_nameList[$name]] {
    male: "Dzwonił {{ $name }}",
    female: "Dzwoniła {{ $name }}",
   *other: "Dzwonił użytkownik {{ $name }}" 
}>

The other key will be used if _nameList[$name] is undefined (neither 'male' nor 'female').

status

accepted for inclusion