data-locales

Generate locales and localized data

Usage no npm install needed!

<script type="module">
  import dataLocales from 'https://cdn.skypack.dev/data-locales';
</script>

README

data-locales

Generate locales and localized data.

stability-wip npm version Commitizen friendly Conventional Commits License CircleCI Coverage Status


How it works

  • It take structured data (JavaScript or JSON);
  • look for $properties ($ leading);
  • create a "locale" string;
  • save it;
  • assign it to new "localized" data file.

Example

Sources

example/test.js

export default {
  test: {
    $localizeMe: 'foo',
    dontTouchMe: 'bar',
  },
}

example/test2.json

{
  "test2": {
    "$localizeMe": "baz",
    "dontTouchMe": "qux"
  }
}

Command

data-locales -e 'example/*.(js|json)' -d 'data' -l 'locales' -f 'EN'

Outputs

data/test.json

{
  "test": {
    "$localizeMe": "test.localizeMe",
    "dontTouchMe": "bar"
  }
}

data/test2.json

{
  "test2": {
    "$localizeMe": "test2.localizeMe",
    "dontTouchMe": "bar"
  }
}

locales/EN.json

{
  "test.localizeMe": "foo",
  "test2.localizeMe": "baz",
}