{"id":24108236,"url":"https://github.com/ekawatani/i18npack","last_synced_at":"2025-06-12T08:06:33.950Z","repository":{"id":1611326,"uuid":"43205036","full_name":"ekawatani/i18npack","owner":"ekawatani","description":"Packs multiple i18n files into a single JSON file.","archived":false,"fork":false,"pushed_at":"2022-12-30T17:45:37.000Z","size":128,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-31T19:26:56.434Z","etag":null,"topics":["i18n","js-yaml","json-schema","l10n","translation","yaml"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ekawatani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-26T12:44:54.000Z","updated_at":"2020-02-23T18:19:27.000Z","dependencies_parsed_at":"2023-01-13T11:15:41.742Z","dependency_job_id":null,"html_url":"https://github.com/ekawatani/i18npack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekawatani%2Fi18npack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekawatani%2Fi18npack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekawatani%2Fi18npack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekawatani%2Fi18npack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ekawatani","download_url":"https://codeload.github.com/ekawatani/i18npack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ekawatani%2Fi18npack/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259227959,"owners_count":22824907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["i18n","js-yaml","json-schema","l10n","translation","yaml"],"created_at":"2025-01-10T23:26:37.422Z","updated_at":"2025-06-12T08:06:33.920Z","avatar_url":"https://github.com/ekawatani.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# i18npack\nKeeps multiple i18n files in a single YAML file.\n\nMost tools that work with i18n data expect translations to be separated by language. i18npack allows you to keep translations for all languages in the same file so you can glance at all translations without switching to another file. It's based on [js-yaml](https://github.com/nodeca/js-yaml) and thus only supports YAML files as source.\n\n## Installation\n```sh\nnpm install i18npack\n```\n\n## Usage\n\n```javascript\nvar i18npack = require('i18npack');\n\n// Use a glob pattern to specify files\ni18npack.generate('translations/**/*.yaml', options);\n\n// ...or pass an array of file names. options is optional.\ni18npack.generate(['file1.yaml', 'file2.yaml']);\n\n// Set default options if you don't want to pass it each time.\ni18npack.settings.languages = ['en'. 'fr'];\n\n// ...and you can reset options later if necessary.\ni18npack.reset();\n```\n\ni18npack supports glob patterns. See [glob](https://github.com/isaacs/node-glob) documentation.\n\n## Examples\n\nGiven these two source files and option `{ languages: ['en', 'fr'] }`,\n\nbio.yaml\n```yaml\nname: \"John Smith\"\njob: !t\n  - \"engineer\"\n  - \"ingénieur\"\n\n```\n\npages.yaml\n```yaml\nindex:\n  pageTitle: !t\n    - \"My Website\"\n    - \"Mon site web\"\n  url: \"http://www.mywebsite.com\"\n\n```\n\nthey are transformed into:\n\nen.json\n```json\n{\n  \"bio\": {\n    \"name\": \"John Smith\",\n    \"job\": \"engineer\"\n  },\n  \"pages\": {\n    \"index\": {\n      \"pageTitle\": \"My Website\",\n      \"url\": \"http://www.mywebsite.com\"\n    }\n  },\n  \"__lang__\": \"en\",\n  \"__langs__\": [\"en\", \"fr\"]\n}\n```\n\nfr.json\n```json\n{\n  \"bio\": {\n    \"name\": \"John Smith\",\n    \"job\": \"ingénieur\"\n  },\n  \"pages\": {\n    \"index\": {\n      \"pageTitle\": \"Mon site web\",\n      \"url\": \"http://www.mywebsite.com\"\n    }\n  },\n  \"__lang__\": \"fr\",\n  \"__langs__\": [\"en\", \"fr\"]\n}\n```\n\nNote that the `__lang__` and `__langs__` are added automatically, but if these placeholders are already taken, then they are not overwritten. Also, you can choose to not include them by default by setting `includeLangDetails` in the options to false.\n\n### Language Keys\n\nIf there are many languages, it may be convenient to prefix each translation by a language code. These codes need to be the same ones specified in `options`. Also, the order is not important, but it is not possible to key only some translations.\n\n```yaml\ngreetingText: !t\n  - en: Welcome!\n  - fr: Bienvenue!\n  - da: Velkommen!\n  - ja: ようこそ！\n```\n\n### i18npack YAML Types\n\ni18npack uses several built-in cusyom YAML types to help you organize strings better.\n\n#### !t\n\nTakes a list of scalars and selects one that corresponds to the current language being generated. The order of the items in the list determine the language, and it corresponds to the order defined in the `languages` option.\n\nSee examples above.\n\n#### !struct\n\nTakes a specified JSON schema and validates a block against the Draft v7 schema using [ajv](https://github.com/epoberezkin/ajv). To specifiy a schema, use `_schema` in the source and specify the name of the file containing it. Use `jsonValidatorOptions` to pass options to the validator (See their documentation for available options). If you are unfamilier with JSON schema Draft v7, try using [http://jsonschema.net](http://jsonschema.net) to generate it.\n\nbook.yaml\n```yaml\nbook: !struct\n  _schema: book.json\n  title: Alice's Adventures in Wonderland\n  auothor: Lewis Carroll\n```\n\nbook.json\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"title\": {\n      \"type\": \"string\"\n    },\n    \"auothor\": {\n      \"type\": \"string\"\n    }\n  },\n  \"required\": [\n    \"title\",\n    \"auothor\"\n  ]\n}\n```\n\n#### !extend\n\nReads a YAML file and [_.extend](https://lodash.com/docs#assign)s the current block with the file content.\n\n```yaml\nbook: !extend\n  _base: book.yaml\n  published: 1865\n```\n\nResult:\n```json\n{\n  \"book\": {\n    \"title\": \"Alice's Adventures in Wonderland\",\n    \"auothor\": \"Lewis Carroll\",\n    \"published\": 1856\n  }\n}\n```\n\n### Custom YAML Types\n\nYou can also specify your own YAML types. See [js-yaml](https://github.com/nodeca/js-yaml) documentation for more details.\n\n```javascript\nvar options = {\n  customTypes: {\n    '!greet scalar': function(value) {\n      return 'Hello, ' + value + '!';\n    },\n    '!max sequence': function(values) {\n      return Math.max.apply(null, values);\n    }\n  }\n};\n\ni18npack.generate('test.yaml', options);\n```\n\ntest.yaml\n```yaml\nmsg: !greet John Smith\nmaxValue: !max\n  - 10\n  - 5\n  - 21\n  - 5\nfoo: !!str 123\nbar: 123\n```\n\nResult:\n\n```json\n{\n  \"test\": {\n    \"msg\": \"Hello, John Smith!\",\n    \"maxValue\": 21,\n    \"foo\": \"123\",\n    \"bar\": 123\n  }\n}\n```\n\n### Using Templates\n\nIt is possible to reference a value from any source files so you don't need to repeat the same values in many places. [JSON Query](https://github.com/mmckegg/json-query) is supported in i18npack to make this possible. To use it, enclose the query in the `{{ }}` delimiter, and\n**wrap it inside double quotes**:\n\nbio.yaml\n```yaml\nname: \"John Smith\",\nhomepage: \"{{ pages.index.url }}\"\n```\n\npages.yaml\n```yaml\nindex:\n  url: \"http://www.mywebsite.com\"\n```\n\nResult:\n\n```yaml\nbio:\n  name: \"John Smith\"\n  homepage: \"http://www.mywebsite.com\"\npages:\n  index:\n    url: \"http://www.mywebsite.com\"\n```\n\n### Handling Empty Strings\n\nBy default, empty strings are not included in the output. To change this behavior, use the `allowEmptyTranslations` option.\n\n## Options\n\nYou can override the default options as follows so you don't need to pass the option object each time. If you need to reset changes, use `i18npack.reset()`.\n\n```javascript\ni18npack.settings.dest = 'data/translations';\n```\n\n### languages\nType: `array`\nDefault: `['en']`\n\nAn array of supported languages.\n\n### dest\nType: `string`\nDefault: `'.'`\n\nThe path of a destination directory.\n\n### schemaDir\nType: `string`\nDefault: `'.'`\n\nThe directory containing schemas for source files.\n\n### includeLangDetails\nType: `boolean`\nDefault: `true`\n\nIf true, the `__lang__` and `__langs__` properties will be added to the output files.\n\n### jsonValidatorOptions\nType: `object`\nDefault: `{}`\n\nThe options passed to the JSON validator.\n\n### delimiter\nType: `RegExp` object\nDefault: `/{{([\\s\\S]+?)}}/g`\n\nThe delimiter used for processing templates. It must have one regex group and the global flag `g`.\n\n### customTypes\nType: `object`\nDefault: `{}`\n\nAn object of key-value pairs containing custom YAML types. See [js-yaml](https://github.com/nodeca/js-yaml) documentation for more details.\n\n### strict\nType: `boolean`\nDefault: `false`\n\nIf true, an error is thrown if the number of provided translations is less than the number of the supported languages.\n\n### allowEmptyTranslations\nType: `boolean`\nDefault: `false`\n\nIf true, empty translations are included in the output.\n\n### ext\nType: `string`\nDefault: `'.json'`\n\nThe file extension of output files.\n\n### mergeFilesAtRoot\nType: `boolean`\nDefault: `false`\n\nIf true, the output of each file will be merged at the root. Otherwise, each file is namespaced by its file name. Note that if there are keys with the same name coming from multiple files, an error will be thrown.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekawatani%2Fi18npack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fekawatani%2Fi18npack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fekawatani%2Fi18npack/lists"}