{"_id":"pseudo-translate-icu","_rev":"3-876cd4723398ca895f8c92e177bd6fd7","name":"pseudo-translate-icu","dist-tags":{"latest":"0.2.2"},"versions":{"0.1.0":{"name":"pseudo-translate-icu","version":"0.1.0","description":"Pseudo translate ICU message strings, objects or entire JSON file","keywords":["i18n","internationalization","l10n","localization","pseudo-translation","pseudo-localization","icu","icu-messageformat","i18next","formatjs","intl-messageformat"],"repository":{"type":"git","url":"git+https://github.com/diptarag/pseudo-translate-icu.git"},"bugs":{"url":"https://github.com/diptarag/pseudo-translate-icu/issues"},"author":{"name":"Diptarag Mukherjee","email":"diptarag@gmail.com"},"license":"MIT","type":"module","main":"dist/pseudo-translate-icu.cjs","module":"dist/pseudo-translate-icu.mjs","scripts":{"build":"rollup -c","lint":"eslint src/*","check-formatting":"prettier --list-different src/**/*.js","format":"prettier --write src/**/*.js","test":"yarn run lint"},"devDependencies":{"@babel/core":"^7.22.17","@babel/preset-env":"^7.22.15","@rollup/plugin-babel":"^6.0.3","@rollup/plugin-commonjs":"^25.0.4","@rollup/plugin-node-resolve":"^15.2.1","babel-jest":"^29.6.4","eslint":"^8.49.0","jest":"^29.6.4","jest-cli":"^29.6.4","prettier":"^3.0.3","rollup":"^3.29.0"},"dependencies":{"@formatjs/icu-messageformat-parser":"^2.6.2"},"gitHead":"5bfe08de7136cc437abbc2f08c68ad32f248a815","homepage":"https://github.com/diptarag/pseudo-translate-icu#readme","_id":"pseudo-translate-icu@0.1.0","_nodeVersion":"18.4.0","_npmVersion":"8.12.1","dist":{"integrity":"sha512-KSJZAFObn4W/0Oaz8uMMynju+8dIWuwZiT7mBXxgDKgp/tUOHPginh5BqDjVDfr7wTA+GqaVbw4DvUXKu6IfTw==","shasum":"0e33ace93b36ca4be61144e0d5ad695835bc0c85","tarball":"https://registry.npmjs.org/pseudo-translate-icu/-/pseudo-translate-icu-0.1.0.tgz","fileCount":5,"unpackedSize":225820,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHPKoDyzw5pt5j9DgN4ivB3SWFuENh1zQ7NH4n1tD1meAiARCm8NsVG812FRWZxF9qUnOraZpTyOF4Josp1Qy48YWg=="}]},"_npmUser":{"name":"diptarag","email":"diptarag@gmail.com"},"directories":{},"maintainers":[{"name":"diptarag","email":"diptarag@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pseudo-translate-icu_0.1.0_1694450242092_0.5439285976671802"},"_hasShrinkwrap":false},"0.2.0":{"name":"pseudo-translate-icu","version":"0.2.0","description":"Pseudo translate ICU message strings, objects or entire JSON file","keywords":["i18n","internationalization","l10n","localization","pseudo-translation","pseudo-localization","icu","icu-messageformat","i18next","formatjs","intl-messageformat"],"repository":{"type":"git","url":"git+https://github.com/diptarag/pseudo-translate-icu.git"},"bugs":{"url":"https://github.com/diptarag/pseudo-translate-icu/issues"},"author":{"name":"Diptarag Mukherjee","email":"diptarag@gmail.com"},"license":"MIT","type":"module","main":"dist/pseudo-translate-icu.cjs","module":"dist/pseudo-translate-icu.mjs","scripts":{"build":"rollup -c","lint":"eslint src/*","check-formatting":"prettier --list-different src/**/*.js","format":"prettier --write src/**/*.js","test":"yarn run lint"},"devDependencies":{"@babel/core":"^7.22.17","@babel/preset-env":"^7.22.15","@rollup/plugin-babel":"^6.0.3","@rollup/plugin-commonjs":"^25.0.4","@rollup/plugin-node-resolve":"^15.2.1","babel-jest":"^29.6.4","eslint":"^8.49.0","jest":"^29.6.4","jest-cli":"^29.6.4","prettier":"^3.0.3","rollup":"^3.29.0"},"dependencies":{"@formatjs/icu-messageformat-parser":"^2.6.2"},"gitHead":"248c44e6b8cc03fbefb3a3217c881f16ae440864","homepage":"https://github.com/diptarag/pseudo-translate-icu#readme","_id":"pseudo-translate-icu@0.2.0","_nodeVersion":"18.4.0","_npmVersion":"8.12.1","dist":{"integrity":"sha512-guLI/b99bMPLJkbYXx6fvCXdZDYIQEvgHHcpfxv8PU3j9VQXhDmPvFnaTE1AKFkp7YOfKP1ZTjRa5dYTurzlUw==","shasum":"753f1e6ee59721d1a3572ac22f4fb59fe9853c0e","tarball":"https://registry.npmjs.org/pseudo-translate-icu/-/pseudo-translate-icu-0.2.0.tgz","fileCount":5,"unpackedSize":228239,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCytKGzuiD0KL6mPSkvktg8a57f+hzB2/MGroFMXezTgQIgNfIMLdtXxsZf6AYJmTblOkxC6ZI+aAbO7FqXyAlvaQQ="}]},"_npmUser":{"name":"diptarag","email":"diptarag@gmail.com"},"directories":{},"maintainers":[{"name":"diptarag","email":"diptarag@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pseudo-translate-icu_0.2.0_1694459039175_0.5545564218986148"},"_hasShrinkwrap":false},"0.2.1":{"name":"pseudo-translate-icu","version":"0.2.1","description":"Pseudo translate ICU message strings, objects or entire JSON file","keywords":["i18n","internationalization","l10n","localization","pseudo-translation","pseudo-localization","icu","icu-messageformat","i18next","formatjs","intl-messageformat"],"repository":{"type":"git","url":"git+https://github.com/diptarag/pseudo-translate-icu.git"},"bugs":{"url":"https://github.com/diptarag/pseudo-translate-icu/issues"},"author":{"name":"Diptarag Mukherjee","email":"diptarag@gmail.com"},"license":"MIT","type":"module","main":"dist/pseudo-translate-icu.cjs","module":"dist/pseudo-translate-icu.mjs","scripts":{"build":"rollup -c","lint":"eslint src/*","check-formatting":"prettier --list-different src/**/*.js","format":"prettier --write src/**/*.js","test":"yarn run lint"},"devDependencies":{"@babel/core":"^7.22.17","@babel/preset-env":"^7.22.15","@rollup/plugin-babel":"^6.0.3","@rollup/plugin-commonjs":"^25.0.4","@rollup/plugin-node-resolve":"^15.2.1","eslint":"^8.49.0","prettier":"^3.0.3","rollup":"^3.29.0"},"dependencies":{"@formatjs/icu-messageformat-parser":"^2.6.2"},"gitHead":"034c687d71d9068b0ee02aa5ee2d870f5685a4ec","homepage":"https://github.com/diptarag/pseudo-translate-icu#readme","_id":"pseudo-translate-icu@0.2.1","_nodeVersion":"18.4.0","_npmVersion":"8.12.1","dist":{"integrity":"sha512-zTp/m/Qgp67nruxKOOu1XidAsYrJTEwKTN6R/rh5WsZ70HPYSqeVNhpxVXK3mAW+ZPsqJ+RImuZYYipcZfczKQ==","shasum":"6b5f9901fc19bc36444eaa7d1974eca453ae3c01","tarball":"https://registry.npmjs.org/pseudo-translate-icu/-/pseudo-translate-icu-0.2.1.tgz","fileCount":5,"unpackedSize":229300,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEtpkAX6Mw+Nh7WoAUQmKMm4byRYvDIo+TYCixTXHVs0AiBskxyYQBXfFvzZqyXkyA+kgqgMJpUmnB/6QTKdAL6odA=="}]},"_npmUser":{"name":"diptarag","email":"diptarag@gmail.com"},"directories":{},"maintainers":[{"name":"diptarag","email":"diptarag@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pseudo-translate-icu_0.2.1_1694536581977_0.8160427787593516"},"_hasShrinkwrap":false},"0.2.2":{"name":"pseudo-translate-icu","version":"0.2.2","description":"Pseudo translate ICU message strings, objects or entire JSON file","keywords":["i18n","internationalization","l10n","localization","pseudo-translation","pseudo-localization","icu","icu-messageformat","i18next","formatjs","intl-messageformat"],"repository":{"type":"git","url":"git+https://github.com/diptarag/pseudo-translate-icu.git"},"bugs":{"url":"https://github.com/diptarag/pseudo-translate-icu/issues"},"author":{"name":"Diptarag Mukherjee","email":"diptarag@gmail.com"},"license":"MIT","type":"module","main":"dist/pseudo-translate-icu.cjs","module":"dist/pseudo-translate-icu.mjs","scripts":{"build":"rollup -c","lint":"eslint src/*","check-formatting":"prettier --list-different src/**/*.js","format":"prettier --write src/**/*.js","test":"yarn run lint"},"devDependencies":{"@babel/core":"^7.22.17","@babel/preset-env":"^7.22.15","@rollup/plugin-babel":"^6.0.3","@rollup/plugin-commonjs":"^25.0.4","@rollup/plugin-node-resolve":"^15.2.1","eslint":"^8.49.0","prettier":"^3.0.3","rollup":"^3.29.0"},"dependencies":{"@formatjs/icu-messageformat-parser":"^2.6.2"},"gitHead":"2aa13b57bbb7cc352555b61055287446a23e987c","homepage":"https://github.com/diptarag/pseudo-translate-icu#readme","_id":"pseudo-translate-icu@0.2.2","_nodeVersion":"18.4.0","_npmVersion":"8.12.1","dist":{"integrity":"sha512-0IEsBrLmZBi+OxMhoRTJsIMOGKzSoLGhej3ihVyo+SVtW8xcfpY1mn4zsNARE1NAq2V+Pnb/nh6AZbbY0NniFA==","shasum":"8cf1adb7d3270e4c3b9eca763f17ed1a7c0d81a9","tarball":"https://registry.npmjs.org/pseudo-translate-icu/-/pseudo-translate-icu-0.2.2.tgz","fileCount":5,"unpackedSize":228836,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBD6C7ifx752dqnDH4BeOzB+l2I9d1VHgXt8PF9tq+xhAiBi33ikTr88nzL1xRtacXJAYUc6+9PKkz78oEWs2K7v+A=="}]},"_npmUser":{"name":"diptarag","email":"diptarag@gmail.com"},"directories":{},"maintainers":[{"name":"diptarag","email":"diptarag@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pseudo-translate-icu_0.2.2_1694542856020_0.4049445311681483"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-11T16:37:22.091Z","0.1.0":"2023-09-11T16:37:22.333Z","modified":"2023-09-12T18:20:56.584Z","0.2.0":"2023-09-11T19:03:59.564Z","0.2.1":"2023-09-12T16:36:22.256Z","0.2.2":"2023-09-12T18:20:56.422Z"},"maintainers":[{"name":"diptarag","email":"diptarag@gmail.com"}],"description":"Pseudo translate ICU message strings, objects or entire JSON file","homepage":"https://github.com/diptarag/pseudo-translate-icu#readme","keywords":["i18n","internationalization","l10n","localization","pseudo-translation","pseudo-localization","icu","icu-messageformat","i18next","formatjs","intl-messageformat"],"repository":{"type":"git","url":"git+https://github.com/diptarag/pseudo-translate-icu.git"},"author":{"name":"Diptarag Mukherjee","email":"diptarag@gmail.com"},"bugs":{"url":"https://github.com/diptarag/pseudo-translate-icu/issues"},"license":"MIT","readme":"# pseudo-translate-icu\n\nGenerate **pseudo translations** for ICU message strings\n> [Ɠḗƞḗřȧŧḗ ƥşḗŭḓǿ ŧřȧƞşŀȧŧīǿƞş ƒǿř ĪƇŬ ḿḗşşȧɠḗ şŧřīƞɠş]\n\n## What is pseudo translation?\n\nPseudo translation is a technique used in internationalization/localization to test and prepare software for translation into other languages. It involves transforming the source text of an application into a simulated or \"pseudo\" foreign language before the actual translation process.\n\n## Why use pseudo translation?\n\n* **Identifying UI Issues**: Pseudo translation helps identify UI and layout issues that may arise when text is translated into languages with different character sets, lengths, or text directionality. It helps developers and designers discover issues such as text overflow, layout misalignment, or clipping.\n\n* **String Extraction Validation**: It helps validate that all strings that need to be translated are properly extracted from the source code.\n\n* **Placeholder Verification**: Pseudo translation helps ensure that placeholders for dynamic content (e.g., variables, data values) are correctly handled. It checks that placeholders are in the correct order and that they do not break the translated text.\n\n* **Text Expansion Testing**: Different languages may require more space to express the same meaning. Pseudo translation simulates text expansion by adding extra characters, allowing developers to test whether the UI can accommodate longer text without layout issues.\n\n* **Text Directionality Issues**: Languages have varying text directionality (e.g., left-to-right or right-to-left). Pseudo translation can include right-to-left characters to test the application's support for bidirectional text.\n\n* **Localization Readiness**: Pseudo translation helps ensure that the application is ready for localization and internationalization. It's an early check to prevent localization issues from surfacing late in the development cycle.\n\n* **Quality Assurance**: It serves as a quality assurance step by uncovering potential issues before the actual translation process. This can save time and resources by addressing problems early.\n\n## Install\n\nInstall using yarn -\n```sh\nyarn add pseudo-translate-icu\n```\nor using npm\n```sh\nnpm install pseudo-translate-icu\n```\n## Usage\n\n### Import or require the module\n\n```javascript\n// Using ESM\nimport { pseudoTranslate, pseudoTranslateJsonFile } from 'pseudo-translate-icu';\n\n// Using CJS\nconst { pseudoTranslate, pseudoTranslateJsonFile } = require('pseudo-translate-icu');\n```\n\n### Translating a string\n\nPseudo translate a string -\n```javascript\nimport { pseudoTranslate } from 'pseudo-translate-icu';\n\nconst translatedText = pseudoTranslate('Hello {name}, Welcome to pseudo-translate-icu doc');\n\n// Output\n// translatedText: [Ħḗŀŀǿ {name}, Ẇḗŀƈǿḿḗ ŧǿ ƥşḗŭḓǿ-ŧřȧƞşŀȧŧḗ-īƈŭ ḓǿƈ]\n// Notice the dynamic segment {name} is not touched. This dynamic variable resolution is usually called interpolation\n```\n\n### Translating a JSON object\n```javascript\nimport { pseudoTranslate } from 'pseudo-translate-icu';\n\nconst texts = {\n  welcome: 'Hello {name}, Welcome to pseudo-translate-icu doc',\n  pluralization: 'Hi {name}, you have {numProducts, plural, =0 {no items} =1 {one item} other {# items}} in cart',\n  pseudo: 'Generate pseudo translations for ICU message strings'\n}\n\nconst translatedText = pseudoTranslate(texts);\n\n// Output\n// translatedText:\n//{\n//  welcome: '[Ħḗŀŀǿ {name}, Ẇḗŀƈǿḿḗ ŧǿ ƥşḗŭḓǿ-ŧřȧƞşŀȧŧḗ-īƈŭ ḓǿƈ]',\n//  pluralization: '[Ħī {name}, ẏǿŭ ħȧṽḗ {numProducts,plural,=0{ƞǿ īŧḗḿş} =1{ǿƞḗ īŧḗḿ} other{# īŧḗḿş}} īƞ ƈȧřŧ]',\n//  pseudo: '[Ɠḗƞḗřȧŧḗ ƥşḗŭḓǿ ŧřȧƞşŀȧŧīǿƞş ƒǿř ĪƇŬ ḿḗşşȧɠḗ şŧřīƞɠş]'\n// }\n```\n\n### Translating a JSON file\nIt's possible to translate an entire JSON file as well -\n\n```javascript\nimport { pseudoTranslateJsonFile } from 'pseudo-translate-icu';\n\nconst translatedText = pseudoTranslateJsonFile('..path/to/json/file');\n\n// Output\n// translatedText:\n//{\n//  \"welcome\": \"[Ħḗŀŀǿ {name}, Ẇḗŀƈǿḿḗ ŧǿ ƥşḗŭḓǿ-ŧřȧƞşŀȧŧḗ-īƈŭ ḓǿƈ]\",\n//  \"pluralization\": \"[Ħī {name}, ẏǿŭ ħȧṽḗ {numProducts,plural,=0{ƞǿ īŧḗḿş} =1{ǿƞḗ īŧḗḿ} other{# īŧḗḿş}} īƞ ƈȧřŧ]\",\n//  \"pseudo\": \"[Ɠḗƞḗřȧŧḗ ƥşḗŭḓǿ ŧřȧƞşŀȧŧīǿƞş ƒǿř ĪƇŬ ḿḗşşȧɠḗ şŧřīƞɠş]\"\n// }\n```\n\n## Options\nBoth ```pseudoTranslate``` and ```pseudoTranslateJsonFile``` take a 2nd argument - ```options``` to customize the translation behavior\n\n```javascript\npseudoTranslate(source: string | object, options: object)\npseudoTranslateJsonFile(sourcePath: string, options: object)\n```\n\nOptions include -\n\n### `enableMarker` - default (`true`)\nBy default translated texts are wrapped around ```[]``` to indicate the text boundary. You can disable the behavior by passing the option ```enableMarker: false```\n```javascript\npseudoTranslate('Hello {name}, Welcome to pseudo-translate-icu doc',\n{\n  enableMarker: false\n});\n\n// Output - Ħḗŀŀǿ {name}, Ẇḗŀƈǿḿḗ ŧǿ ƥşḗŭḓǿ-ŧřȧƞşŀȧŧḗ-īƈŭ ḓǿƈ\n```\n\n### `startMarker` - default (`'['`) & `endMarker` - default (`']'`)\nIf marker is enabled then default ```startMarker``` is `[` & ```endMarker``` is `]`. But you can configure the start and end marker -\n```javascript\npseudoTranslate('Hello {name}, Welcome to pseudo-translate-icu doc',\n{\n  startMarker: '<< ',\n  endMarker: ' >>'\n});\n\n// Output - << Ħḗŀŀǿ {name}, Ẇḗŀƈǿḿḗ ŧǿ ƥşḗŭḓǿ-ŧřȧƞşŀȧŧḗ-īƈŭ ḓǿƈ >>\n```\n\n### `expand` - default (`false`) & `expandPercentage` - default (`30`)\nSimulating text expansion is a crucial use case of pseudo translation. You can enable text expandsion by using the flag `expand: true`. By default 30% expandsion will happen, but you can configure the expansion percentage using the option `expandPercentage`.\nExpansion works by randomly duplicating some words.\n```javascript\npseudoTranslate('Hello {name}, Welcome to pseudo-translate-icu doc',\n{\n  expand: true\n});\n\n // Output - [Ħḗŀŀǿ {name}, Ẇḗŀƈǿḿḗ Ẇḗŀƈǿḿḗ ŧǿ ƥşḗŭḓǿ-ŧřȧƞşŀȧŧḗ-īƈŭ ḓǿƈ]\n```\n\n### `strategy` - default (`'accented'`)\n\n2 strategies for pseudo translations are supported -\n\n* **accented** - In Accented English all Latin letters are replaced by accented Unicode counterparts which don't impair the readability of the content. This allows developers to quickly test if any given string is being correctly displayed in its 'translated' form. This is the default strategy and so far all examples use `accented` strategy.\n\n* **bidi** - Bidi English is a fake RTL locale.  All words are surrounded by Unicode formatting marks forcing the RTL directionality of characters. In addition, to make the reversed text easier to read, individual letters are flipped.\nTo set `bidi` strategy -\n```javascript\npseudoTranslate('Welcome to pseudo-translate-icu doc',\n{\n  strategy: 'bidi'\n});\n\n// Output - ‮Mǝʅɔoɯǝ ʇo dsǝnpo-ʇɹɐusʅɐʇǝ-ıɔn poɔ‬\n```\n\n### `i18nextTrans` - default (`false`)\nIf you are using `react-i18next` with ICU, you will encounter situations where you need to externalize HTML elements. For react-i18next, the recommended method is [Trans component](https://react.i18next.com/latest/trans-component).\nBut the resultant string of Trans component is not compatible with ICU parser. And you may recieve an error ```SyntaxError: UNMATCHED_CLOSING_TAG```\nTo get around the problem, use the option ```i18nextTrans: true```.\n\n## Credits\n\n* The accented & bidi strategy is picked from the [mozilla code](https://hg.mozilla.org/mozreview/gecko/rev/a96cf6ff334617c3d51e325ece5f27eaa0fefac9)\n* I only built this library as [icu-pseudo-translate](https://github.com/1stdibs/icu-pseudo-translate) could not meet many of my requirements. But I picked up the core parsing logic from the library.\n","readmeFilename":"README.md"}