L20n/Features/Switch expression

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


Common case for macros and expressions in case of L20n will be a need to select an option from a group of choices. Plural form, gender, etc. Currently we're offering conditional expressions that can be nested to achieve the goal:

<plural(n) { 
  n<=0 ? 
    "zero" : 
    n<1 ? 
      "almost" : 
      n==1 ? 
        "one" : "many"


<plural(n) {
  switch {
    n<=0: 'zero',
    n<1: 'almost',
    n==1: 'one',
    default: 'many'

Because of the nature of expressions in L20n and its use cases, we do not believe that switch clause would make sense in the traditional sense (JS, Python, etc.). We'd either have to use rust-like pattern matching, or go fully into expressions (like in the example above).


  • gandalf - postpone till at least 1.1
  • stas - l20n.next
  • pike - ?