{"id":18582944,"url":"https://github.com/messageformat/gettext-to-messageformat","last_synced_at":"2025-04-10T11:36:38.394Z","repository":{"id":26841343,"uuid":"110761755","full_name":"messageformat/gettext-to-messageformat","owner":"messageformat","description":"Convert gettext input (po/pot/mo files) into messageformat-compatible JSON","archived":false,"fork":false,"pushed_at":"2023-03-04T02:28:38.000Z","size":21,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T03:57:33.317Z","etag":null,"topics":["gettext","messageformat"],"latest_commit_sha":null,"homepage":"","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/messageformat.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-15T00:23:17.000Z","updated_at":"2022-03-17T16:32:12.000Z","dependencies_parsed_at":"2024-06-18T18:16:04.234Z","dependency_job_id":"f92171cf-aef6-4182-9843-cfe6266d50cc","html_url":"https://github.com/messageformat/gettext-to-messageformat","commit_stats":null,"previous_names":["eemeli/gettext-to-messageformat"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/messageformat%2Fgettext-to-messageformat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/messageformat%2Fgettext-to-messageformat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/messageformat%2Fgettext-to-messageformat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/messageformat%2Fgettext-to-messageformat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/messageformat","download_url":"https://codeload.github.com/messageformat/gettext-to-messageformat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208689,"owners_count":21065205,"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":["gettext","messageformat"],"created_at":"2024-11-07T00:17:21.123Z","updated_at":"2025-04-10T11:36:33.343Z","avatar_url":"https://github.com/messageformat.png","language":"JavaScript","readme":"# gettext-to-messageformat\n\nConverts gettext input (po/pot/mo files) into [messageformat]-compatible JSON,\nusing [gettext-parser].\n\n\n### Installation\n\n```sh\nnpm install --save gettext-to-messageformat\n```\nor\n```sh\nyarn add gettext-to-messageformat\n```\n\nIf using in an environment that does not natively support ES6 features such as\nobject destructuring and arrow functions, you'll want to use a transpiler for this.\n\n\n### Usage\n\n```js\nconst { parsePo, parseMo } = require('gettext-to-messageformat')\nconst { headers, pluralFunction, translations } = parsePo(`\n# Examples from http://pology.nedohodnik.net/doc/user/en_US/ch-poformat.html\nmsgid \"\"\nmsgstr \"\"\n\"Content-Type: text/plain; charset=UTF-8\\n\"\n\"Language: pl\\n\"\n\"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10\u003e=2 \u0026\u0026 n%10\u003c=4 \u0026\u0026 (n%100\u003c10 || n%100\u003e=20) ? 1 : 2);\\n\"\n\nmsgid \"Time: %1 second\"\nmsgid_plural \"Time: %1 seconds\"\nmsgstr[0] \"Czas: %1 sekunda\"\nmsgstr[1] \"Czas: %1 sekundy\"\nmsgstr[2] \"Czas: %1 sekund\"\n\nmsgid \"%1 took %2 ms to complete.\"\nmsgstr \"Trebalo je %2 ms da se %1 završi.\"\n\nmsgid \"%s took %d ms to complete.\"\nmsgstr \"Trebalo je %2$d ms da se %1$s završi.\"\n\nmsgid \"No star named %(starname)s found.\"\nmsgstr \"Nema zvezde po imenu %(starname)s.\"\n`)\n\nconst MessageFormat = require('messageformat')\nconst mf = new MessageFormat({ [headers.Language]: pluralFunction })\nconst messages = mf.compile(translations)\n\nmessages['Time: %1 second']([1])\n// 'Czas: 1 sekunda'\n\nmessages['%s took %d ms to complete.'](['TASK', 42])\n// 'Trebalo je 42 ms da se TASK završi.'\n\nmessages['No star named %(starname)s found.']({ starname: 'Chi Draconis' })\n// 'Nema zvezde po imenu Chi Draconis.'\n```\n\nFor more examples, [gettext-parser] includes a selection of `.po` and `.mo` files\nin its test fixtures.\n\n\n### API: `parseMo(input, options)` and `parsePo(input, options)`\n\nThe two functions differ only in their expectation of the input's format. `input`\nmay be a string or a Buffer; `options` is an optional set of configuration for\nthe parser, including the following fields:\n\n- `defaultCharset` (string, default `null`) – For Buffer input only, sets the\n  default charset -- otherwise UTF-8 is assumed\n\n- `forceContext` (boolean, default `false`) – If any of the gettext messages\n  define a `msgctxt`, that is used as a top-level key in the output, and all\n  messages without a context are included under the `''` empty string context.\n  If no context is set, by default this top-level key is not included unless\n  `forceContext` is set to `true`.\n\n- `pluralFunction` (function) – If your input file does not include a Plural-Forms\n  header, or if for whatever reason you'd prefer to use your own, set this to be\n  a stringifiable function that takes in a single variable, and returns the\n  appropriate pluralisation category. Following the model used internally in\n  [messageformat], the function variable should also include `cardinal` as a\n  member array of its possible categories, in the order corresponding to the\n  gettext pluralisation categories. This is relevant if you'd like to avoid the\n  `new Function` constructor otherwise used to generate `pluralFunction`, or to\n  allow for more fine-tuned categories than gettext allows, e.g. differentiating\n  between the categories of `'1.0'` and `'1'`.\n\n- `verbose` (boolean, default `false`) – If set to `true`, missing translations\n  will cause warnings.\n\nFor more options, take a look at the [source](./index.js).\n\nBoth functions return an object containing the following fields:\n\n- `headers` (object) – The raw contents of the input file's headers, with keys\n  using canonical casing.\n- `pluralFunction` (function) – An appropriate pluralisation function to use for\n  the output translations, suitable to be used directly by [messageformat]. May\n  be `null` if none was set in `options` and if the input did not include a\n  Plural-Forms header.\n- `translations` (object) – An object containing the MessageFormat strings keyed\n  by their `msgid` and if used, `msgctxt`.\n\n[messageformat]: https://messageformat.github.io/\n[gettext-parser]: https://github.com/smhg/gettext-parser\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmessageformat%2Fgettext-to-messageformat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmessageformat%2Fgettext-to-messageformat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmessageformat%2Fgettext-to-messageformat/lists"}