{"id":13454594,"url":"https://github.com/nodeca/babelfish","last_synced_at":"2025-04-05T01:08:26.926Z","repository":{"id":1947020,"uuid":"2876698","full_name":"nodeca/babelfish","owner":"nodeca","description":"human friendly i18n for javascript (node.js + browser)","archived":false,"fork":false,"pushed_at":"2023-06-19T03:44:03.000Z","size":433,"stargazers_count":249,"open_issues_count":1,"forks_count":17,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-04-14T02:43:36.961Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://nodeca.github.com/babelfish","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/nodeca.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"open_collective":"puzrin","patreon":"puzrin"}},"created_at":"2011-11-29T17:26:48.000Z","updated_at":"2023-12-15T11:04:18.000Z","dependencies_parsed_at":"2023-07-05T21:01:38.139Z","dependency_job_id":null,"html_url":"https://github.com/nodeca/babelfish","commit_stats":{"total_commits":324,"total_committers":8,"mean_commits":40.5,"dds":0.5092592592592593,"last_synced_commit":"40c20f111b07320697db93346fb789279436f6f1"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fbabelfish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fbabelfish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fbabelfish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodeca%2Fbabelfish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodeca","download_url":"https://codeload.github.com/nodeca/babelfish/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245984859,"owners_count":20704857,"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":[],"created_at":"2024-07-31T08:00:55.671Z","updated_at":"2025-03-29T00:10:16.328Z","avatar_url":"https://github.com/nodeca.png","language":"JavaScript","readme":"BabelFish - human friendly i18n for JS\n======================================\n\n[![CI](https://github.com/nodeca/babelfish/actions/workflows/ci.yml/badge.svg)](https://github.com/nodeca/babelfish/actions/workflows/ci.yml)\n[![NPM version](https://img.shields.io/npm/v/babelfish.svg?style=flat)](https://www.npmjs.org/package/babelfish)\n[![Coverage Status](https://img.shields.io/coveralls/nodeca/babelfish/master.svg?style=flat)](https://coveralls.io/r/nodeca/babelfish?branch=master)\n\n\u003e Internationalization with easy syntax for node.js and browser.\n\nClassic solutions use multiple phrases for plurals. `Babelfish` defines plurals\ninline instead - that's more compact, and easy for programmers. Also, phrases\nare grouped into nested scopes, like in Ruby.\n\n`BabelFish` supports all plural rules from [unicode CLDR](http://cldr.unicode.org/index/charts)\n(via [plurals-cldr](https://github.com/nodeca/plurals-cldr)).\n\n\n### Installation\n\n__node.js:__\n\n```bash\n$ npm install babelfish\n```\n\n__browser:__\n\n```bash\n$ bower install babelfish\n```\n\nUse [es5-shim](https://github.com/es-shims/es5-shim) for old browsers\ncompatibility.\n\n\n### Phrases Syntax\n\n- `#{varname}` Echoes value of variable\n- `((Singular|Plural1|Plural2)):count` Plural form\n\nexample:\n\n- `А у меня в кармане #{nails_count} ((гвоздь|гвоздя|гвоздей)):nails_count`\n\nYou can also omit anchor variable for plurals, by default it will be `count`.\nThus following variants are equal:\n\n- `I have #{count} ((nail|nails))`\n- `I have #{count} ((nail|nails)):count`\n\nAlso you can use variables in plural parts:\n\n- `I have ((#{count} nail|#{count} nails))`\n\nNeed special zero form or overwrite any specific value? No problems:\n\n- `I have ((=0 no nails|#{count} nail|#{count} nails))`\n\n\n##### Escape chars\n\nIf you need `#{`, `((`, `|` or `))` somewhere in text, where it can be considered\nas markup part - just escape them with `\\`.\n\n\n##### Example with YAML\n\nAs BabelFish flatten scopes, it's really fun and nice to store translations in\nYAML files:\n\n```yaml\n---\nru-RU:\n  profile: Профиль\n  forums: Форумы\n  apps:\n    forums:\n      new_topic: Новая тема\n      last_post:\n        title : Последнее сообщение\n        by : от\n  demo:\n    apples: \"На столе лежит #{count} ((яблоко|яблока|яблок))\"\n```\n\n### Usage\n\n```javascript\n// Create new instance of BabelFish with default language/locale: 'en-GB'\nvar BabelFish = require('babelfish');\nvar i18n = new BabelFish('en-GB');\n\n\n// Fill in some phrases\ni18n.addPhrase('en-GB', 'demo.hello',         'Hello, #{user.name}.');\ni18n.addPhrase('en-GB', 'demo.conv.wazup',    'Whats up?');\ni18n.addPhrase('en-GB', 'demo.conv.alright',  'Alright, man!');\ni18n.addPhrase('en-GB', 'demo.coerce',        'Total: #{count}.');\n\ni18n.addPhrase('ru-RU', 'demo.hello',         'Привет, #{user.name}.');\ni18n.addPhrase('ru-RU', 'demo.conv.wazup',    'Как дела?');\n\ni18n.addPhrase('uk-UA', 'demo.hello',         'Здоровенькі були, #{user.name}.');\n\n\n// Set locale fallback to use the most appropriate translation when possible\ni18n.setFallback('uk-UA', 'ru-RU');\n\n\n// Translate\nvar params = {user: {name: 'ixti'}};\n\ni18n.t('ru-RU', 'demo.hello', params);  // -\u003e 'Привет, ixti.'\ni18n.t('ru-RU', 'demo.conv.wazup');     // -\u003e 'Как дела?'\ni18n.t('ru-RU', 'demo.conv.alright');   // -\u003e 'Alright, man!'\n\ni18n.t('uk-UA', 'demo.hello', params);  // -\u003e 'Здоровенькі були, ixti.'\ni18n.t('uk-UA', 'demo.conv.wazup');     // -\u003e 'Как дела?'\ni18n.t('uk-UA', 'demo.conv.alright');   // -\u003e 'Alright, man!'\n\n// When params is number or strings, it will be coerced to\n// `{ count: XXX, value: XXX }` - use any of those in phrase.\ni18n.t('en-GB', 'demo.coerce', 5);      // -\u003e 'Total: 5.'\n\n\n// You may wish to \"dump\" translations to load in browser later\n// Dump will include all fallback translations and fallback rules\nvar locale_dump = i18n.stringify('ru-RU');\n\nvar i18n_new = require('babelfish')('en-GB'); // init without `new` also works\ni18n_new.load(locale_dump);\n\n\n// Use objects instead of strings (object/array/number/boolean) - can be\n// useful to prepare bulk data for external libraries.\n// Note, only JSON-supported types are ok (no date \u0026 regex)\ni18n.addPhrase('en-GB', 'demo.boolean',  true);\ni18n.addPhrase('en-GB', 'demo.number',   123);\ni18n.addPhrase('en-GB', 'demo.array',    [1, 2, 3]);\n// fourth param required for hashes (objects) to disable flattening,\n// other types are autodetected\ni18n.addPhrase('en-GB', 'demo.array',    { foo:1, bar:\"2\" }, false);\n```\n\n\n### Implementations in other languages\n\n- Perl - [Locale::Babelfish](https://metacpan.org/pod/Locale::Babelfish)\n- Ruby - https://github.com/regru/babelfish-ruby\n\n\n### License\n\nView the [LICENSE](https://github.com/nodeca/babelfish/blob/master/LICENSE) file (MIT).\n","funding_links":["https://opencollective.com/puzrin","https://patreon.com/puzrin"],"categories":["Packages","Repository","包","目录","Text"],"sub_categories":["Text","Text/String","文本","文本处理"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeca%2Fbabelfish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodeca%2Fbabelfish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodeca%2Fbabelfish/lists"}