Skip to content

Instantly share code, notes, and snippets.

@apipkin
Created December 12, 2013 19:49
Show Gist options
  • Save apipkin/7934232 to your computer and use it in GitHub Desktop.
Save apipkin/7934232 to your computer and use it in GitHub Desktop.

http://wiki.ecmascript.org/doku.php?id=globalization:messageformatting

['Some text before', {
    type: 'plural',  // can be plural or gender/select
    valueName: 'numPeople',  // placeholder for switch value
    offset: 1,  // optional for plural, invalid for select
    one: 'Some message ${ph} with ${#} value', // no gender specific msg necessary
    few: [ 'Optional prefix text for |few|', {
       type: 'select',
       valueName: 'gender',
       male: 'Text for male option with \' single quotes',
       female: 'Text for female option with {}',  // {} produces {} in the output.
       other: 'Text for default'
    }, 'optional postfix text']],
    other: 'Some messages for the default', // no gender specific msg necessary
    '1': [ 'Optional prefix text', {
       type: 'select'
       valueName: 'gender',
       male: 'Text for male option with \' single quotes',
       female: 'Text for female option with {}',  // {} produces {} in the output.
       other: 'Text for default'
    }, 'optional postfix text']],
}, 'and text after']

Proposed option:

['Some text before', {
    type: 'plural',  // can be plural or gender/select
    valueName: 'numPeople',  // placeholder for switch value
    offset: 1,  // optional for plural, invalid for select
    options: {
        one: 'Some message ${ph} with ${#} value', // no gender specific msg necessary
        few: [ 'Optional prefix text for |few|', {
           type: 'select',
           valueName: 'gender',
           options: {
               male: 'Text for male option with \' single quotes',
               female: 'Text for female option with {}',  // {} produces {} in the output.
               other: 'Text for default'
           }
        }, 'optional postfix text'],
        
        other: 'Some messages for the default', // no gender specific msg necessary
        
        '1': [ 'Optional prefix text', {
           type: 'select'
           valueName: 'gender',
           options: {
               male: 'Text for male option with \' single quotes',
               female: 'Text for female option with {}',  // {} produces {} in the output.
               other: 'Text for default'
           }
        }, 'optional postfix text'],
    }
}, 'and text after']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment