martinandert / counterpart

A translation and localization library for Node.js and the browser.
MIT License
242 stars 25 forks source link

split confusion #39

Closed Maxhodges closed 7 years ago

Maxhodges commented 7 years ago

I'm unclear about what the docs are saying about 'splitting'. Can someone explain better? This doesn't seem grammatical to me

The separator option allows you to change what the key gets split via for nested objects. It also allows you to stop counterpart splitting keys if you have a flat object structure:

martinandert commented 7 years ago

Hi Max,

let's assume you have the following translation registered:

{
  en: {
    foo: {
      bar: 'baz'
    }
  }
}

As the dot (.) is the default separator, you can get the value of the translation by simply calling

translate('foo.bar', { locale: 'en' }) //=> 'baz'

If for whatever reason you cannot use the dot character (perhaps because you already use it as part of the individual (sub)keys, for example fo.o), you can switch to a different separator character like this:

translate('foo/bar', { locale: 'en', separator: '/' }) //=> 'baz'

I hope this answers you question. If not, please let me know!