{"_id":"unprefixed-intl","_rev":"36-2ddf13abf2abe1b34c301cf56c12d373","time":{"created":"2023-11-01T05:51:11.337Z","1.0.0":"2023-10-30T06:46:09.787Z","modified":"2023-11-05T05:26:53.568Z","1.0.1":"2023-10-30T06:48:41.896Z","1.0.3":"2023-10-30T06:52:11.820Z","1.0.4":"2023-10-30T06:53:17.477Z","1.0.5":"2023-10-30T07:24:09.224Z","1.0.6":"2023-10-30T07:27:42.184Z","1.0.7":"2023-10-30T07:29:33.600Z","1.0.8":"2023-10-30T07:32:23.360Z","1.0.9":"2023-10-30T18:09:48.910Z","1.1.0":"2023-10-30T18:14:13.921Z","1.1.1":"2023-10-30T18:15:55.051Z","1.1.2":"2023-10-30T18:31:41.613Z","1.1.3":"2023-10-30T18:40:12.889Z","1.1.4":"2023-10-30T18:42:05.964Z","1.1.5":"2023-10-30T18:44:16.156Z","1.1.7":"2023-10-30T19:16:19.504Z","1.1.8":"2023-10-30T19:27:55.702Z","1.1.9":"2023-10-30T19:41:45.181Z","1.2.0":"2023-10-30T19:53:33.941Z","1.2.1":"2023-10-30T19:59:58.480Z","1.2.2":"2023-10-30T20:06:01.441Z","1.2.3":"2023-10-30T20:12:55.458Z","1.2.4":"2023-10-30T20:28:49.747Z","1.2.5":"2023-10-30T20:31:25.845Z","1.2.6":"2023-10-30T20:42:11.312Z","1.2.7":"2023-10-30T20:52:47.511Z","1.2.8":"2023-10-30T21:02:01.814Z","1.2.9":"2023-10-31T00:02:12.912Z","1.3.0":"2023-10-31T00:06:30.843Z","1.3.1":"2023-10-31T00:08:13.728Z","1.3.2":"2023-10-31T00:09:48.545Z","1.3.3":"2023-10-31T00:33:18.611Z","1.3.4":"2023-10-31T00:36:23.873Z","3.0.0":"2023-11-01T05:51:11.550Z","3.1.0":"2023-11-01T18:08:05.859Z","3.1.2":"2023-11-05T05:26:53.371Z"},"name":"unprefixed-intl","dist-tags":{"latest":"3.1.2"},"versions":{"3.0.0":{"name":"unprefixed-intl","version":"3.0.0","description":"An i18n library enabling translations without URL prefixes","main":"dist/index.js","types":"dist/index.d.js","repository":{"type":"git","url":"git+https://github.com/PetalFan/unprefixed-intl.git"},"author":{"name":"PetalFan"},"license":"MIT","private":false,"dependencies":{"@types/node":"^18.0.0","typescript":"^5.0.0"},"keywords":["intl","internationalization","localization","translate","translation"],"gitHead":"5fb19aab5f411ea0755f41bd862bcc7375323854","bugs":{"url":"https://github.com/PetalFan/unprefixed-intl/issues"},"homepage":"https://github.com/PetalFan/unprefixed-intl#readme","_id":"unprefixed-intl@3.0.0","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-AnX4vnuMGhdEuWA45FAIfuPe9MX7Y069KlTeu7dc0Y/xKqvOecYY82Gpg90PZhEMUgE//9qoUQTRI/q7CLQ6iw==","shasum":"8b38ca97912af4506f2caafd0c6fe9bd0ac040c7","tarball":"https://registry.npmjs.org/unprefixed-intl/-/unprefixed-intl-3.0.0.tgz","fileCount":12,"unpackedSize":15790,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG4TPfVlNaoqaSMhf0b43csbznq92k3H3UaCceTUPMYxAiBh3CxqDtt/ZIcSF8Przl9HT9S8l1qYcCN8Ku4AlBDiSA=="}]},"_npmUser":{"name":"petalfan","email":"petalfan.backup@gmail.com"},"directories":{},"maintainers":[{"name":"petalfan","email":"petalfan.backup@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unprefixed-intl_3.0.0_1698817871337_0.4113749838250773"},"_hasShrinkwrap":false},"3.1.0":{"name":"unprefixed-intl","version":"3.1.0","description":"An i18n library enabling translations without URL prefixes","main":"dist/index.js","types":"dist/index.d.js","repository":{"type":"git","url":"git+https://github.com/PetalFan/unprefixed-intl.git"},"author":{"name":"PetalFan"},"license":"MIT","private":false,"dependencies":{"@types/node":"^18.0.0","typescript":"^5.0.0"},"keywords":["intl","internationalization","localization","translate","translation"],"gitHead":"5fb19aab5f411ea0755f41bd862bcc7375323854","bugs":{"url":"https://github.com/PetalFan/unprefixed-intl/issues"},"homepage":"https://github.com/PetalFan/unprefixed-intl#readme","_id":"unprefixed-intl@3.1.0","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-LleFfdkJlcucuEo3CCYQdryznQRFIYFVMuPOBYnwa7KZsiQNx6unasg3SVmXtinlD5Z24qhOI2q7Njp/2TEZoA==","shasum":"bd8f99e91fd175ecfd3559f01e6f0ebade5c620f","tarball":"https://registry.npmjs.org/unprefixed-intl/-/unprefixed-intl-3.1.0.tgz","fileCount":12,"unpackedSize":15965,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDfXw82Oc931J7mzmkVBWoYdwpTe6BXwGesD05PIckm8AiEA6aGs7+KhGikw8NRLucDeUBV5E4RvmRSwkMRkMKd+8pE="}]},"_npmUser":{"name":"petalfan","email":"petalfan.backup@gmail.com"},"directories":{},"maintainers":[{"name":"petalfan","email":"petalfan.backup@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unprefixed-intl_3.1.0_1698862085453_0.7098811108968115"},"_hasShrinkwrap":false},"3.1.2":{"name":"unprefixed-intl","version":"3.1.2","description":"An i18n library enabling translations without URL prefixes","main":"dist/index.js","types":"dist/index.d.js","repository":{"type":"git","url":"git+https://github.com/PetalFan/unprefixed-intl.git"},"author":{"name":"PetalFan"},"license":"MIT","private":false,"dependencies":{"@types/node":"^18.0.0","typescript":"^5.0.0"},"keywords":["intl","internationalization","localization","translate","translation"],"gitHead":"36718681fe2cd04c640c2494d2d3f954fdcc0470","bugs":{"url":"https://github.com/PetalFan/unprefixed-intl/issues"},"homepage":"https://github.com/PetalFan/unprefixed-intl#readme","_id":"unprefixed-intl@3.1.2","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-ogrLlC+go7qbFsPMPi/VWiHK5ZTeLqZErjt89cVwfyY9UUphiZDtz+8u3fBWzB32Og5AazbUEHen96wYmYt3Jw==","shasum":"0972322d26b9d55c6ae44fe1ff43820d907aab06","tarball":"https://registry.npmjs.org/unprefixed-intl/-/unprefixed-intl-3.1.2.tgz","fileCount":12,"unpackedSize":27166,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDv7pXHUiuM444RQ61afewUkSvU+DGtqOjBFAuwAp+bygIhAPGxHxwCkv76DYpSeijujBBpW97IOSmpbP/P2jW87MRv"}]},"_npmUser":{"name":"petalfan","email":"petalfan.backup@gmail.com"},"directories":{},"maintainers":[{"name":"petalfan","email":"petalfan.backup@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/unprefixed-intl_3.1.2_1699162013146_0.25531411823608674"},"_hasShrinkwrap":false}},"maintainers":[{"name":"petalfan","email":"petalfan.backup@gmail.com"}],"description":"An i18n library enabling translations without URL prefixes","homepage":"https://github.com/PetalFan/unprefixed-intl#readme","keywords":["intl","internationalization","localization","translate","translation"],"repository":{"type":"git","url":"git+https://github.com/PetalFan/unprefixed-intl.git"},"author":{"name":"PetalFan"},"bugs":{"url":"https://github.com/PetalFan/unprefixed-intl/issues"},"license":"MIT","readme":"# unprefixed-intl\r\nAn i18n library enabling translations without URL prefixes\r\n\r\nThere is a wrapper for next.js [here](https://www.npmjs.com/package/next-unprefixed-intl/)\r\n\r\n# Usage\r\nAdd an `unprefixed-intl.config.json` file to the project root:\r\n```json\r\n{\r\n  \"messagesPath\": \"/src/messages\",\r\n  \"defaultLang\": \"en\",\r\n  \"maxAcceptedLanguageSearch\": 3,\r\n  \"allowLanguageCode\": true\r\n}\r\n```\r\n\r\nThat will result in the interface (will be used by the package):\r\n```typescript\r\ninterface Config{\r\n    /** Path for the `messages` folder, that will alloc the .json files with the translations, (en-US.json, ...) */\r\n    messagesPath:string,\r\n    /** The default language, that will be used if the preferred language was not found */\r\n    defaultLang:string,\r\n    /** From the list of preferred languages a loop will be run to look for the best match available, this is the\r\n     * limit of iterations this loop can do */\r\n    maxAcceptedLanguageSearch:number\r\n    /** If true: if the complete code is not found, the language code can be used instead, e.g. if the preferred\r\n     * language is `en-US`, but there is no `en-US.json` file but rather a ` en.json`, it will be used */\r\n    allowLanguageCode:boolean\r\n}\r\n```\r\n\r\nAdd the translation files inside the `messagesPath` directory:\r\n\r\n`en` language example: `/src/messages/en.json`\r\n```json\r\n{\r\n  \"Home.component1\": {\r\n    \"hello_message\": \"Hello! Welcome!\",\r\n    \"phrase\": \"I just got my driver's license, and now I need to get gas for my truck. In the fall, I'll enroll in college, and I'll make sure to check the schedule of my favorite soccer team.\"\r\n  },\r\n  \"Home.component2\": {\r\n    \"popup.warning_message\": \"Remember that the default translation file, defined in `defaultLang`, must exist!\"\r\n  }\r\n}\r\n```\r\n`es` language example: `/src/messages/es.json`\r\n```json\r\n{\r\n  \"Home.component1\": {\r\n    \"hello_message\": \"¡Hola! ¡Sea bienvenido!\",\r\n    \"phrase\": \"Acabo de obtener mi licencia de conducir y ahora necesito gasolina para mi camión. En el otoño, me inscribiré en la universidad y me aseguraré de consultar el calendario de mi equipo de fútbol favorito.\"\r\n  },\r\n  \"Home.component2\": {\r\n    \"popup.warning_message\": \"Recuerde que el archivo de traducción predeterminado, definido en `defaultLang`, ¡debe existir!\"\r\n  }\r\n}\r\n```\r\n`en-GB` language example: `/src/messages/en-GB.json`\r\n```json\r\n{\r\n  \"Home.component1\": {\r\n    \"hello_message\": \"Hello! Welcome!\",\r\n    \"phrase\": \"I've just got my driving licence, and now I need to get petrol for my lorry. In the autumn, I'll enrol in university, and I'll make sure to check the timetable of my favourite football team.\"\r\n  },\r\n  \"Home.component2\": {\r\n    \"popup.warning_message\": \"Remember that the default translation file, defined in `defaultLang`, must exist!\"\r\n  }\r\n}\r\n```\r\n\r\n# In the place you want to read the translations:\r\n\r\n`/src/app/page.tsx`\r\n```typescript jsx\r\nimport { getTranslations } from \"unprefixed-intl\"\r\n\r\nconst acceptLanguages = [\"en-US\",\"en\"]\r\n\r\n/*\r\nhere you will receive the function that returns the \r\ntranslations, based on a path (`\"Home.component1\"`), \r\nand a string array (`acceptLanguages`), the order of \r\nthe elements of this array is important, as it \r\ndetermines which translations will be prioritized\r\n */\r\nconst t = getTranslations(\"Home.component1\", acceptLanguages)\r\n```\r\n\r\n# In addition\r\nYou can use `generate` to generate files based in translations api, in that example, the [Google Cloud Translate api](https://www.npmjs.com/package/@google-cloud/translate)\r\n```typescript\r\nimport { generate } from \"unprefixed-intl\"\r\nimport { v2 } from \"@google-cloud/translate\"\r\n\r\nconst CREDENTIALS = JSON.parse(/*secret, check the Google Cloud Translation api for more info*/)\r\n\r\nconst translate = new v2.Translate({\r\n    credentials: CREDENTIALS,\r\n    projectId: CREDENTIALS.project_id,\r\n})\r\n\r\nasync function translateTextFromSource(\r\n    text: string,\r\n    sourceLanguage: string,\r\n    targetLanguage: string,\r\n) {\r\n    const [response] = await translate.translate(text, {\r\n        from: sourceLanguage,\r\n        to: targetLanguage,\r\n    })\r\n    return response\r\n}\r\n\r\nconst fromLanguage = \"en\"\r\ngenerate(\r\n    fromLanguage,\r\n    [\r\n        //[\"en\", \"en\"], // English\r\n        [\"zh\", \"zh\"], // Chinese Mandarin\r\n        [\"hi\", \"hi\"], // Hindi\r\n        [\"es\", \"es\"], // Spanish\r\n        [\"fr\", \"fr\"], // French\r\n        [\"ar\", \"ar\"], // Arabic\r\n        [\"bn\", \"bn\"], // Bengali\r\n        [\"ru\", \"ru\"], // Russian\r\n        [\"pt-BR\", \"pt\"], // Portuguese from Brazil\r\n        [\"pt-PT\", \"pt-PT\"], // Portuguese from Portugal\r\n        [\"pt\", \"pt\"], // Portuguese\r\n        [\"id\", \"id\"], // Indonesian\r\n        [\"de\", \"de\"], // German\r\n        [\"ja\", \"ja\"], // Japanese\r\n        [\"ur\", \"ur\"], // Urdu\r\n        [\"it\", \"it\"], // Italian\r\n        [\"ko\", \"ko\"], // Korean\r\n        [\"tr\", \"tr\"], // Turkish\r\n        [\"vi\", \"vi\"], // Vietnamese\r\n        [\"pl\", \"pl\"], // Polish\r\n        [\"jv\", \"jv\"], // Javanese\r\n        [\"pa\", \"pa\"], // Punjabi\r\n    ],\r\n    (text, to) => translateTextFromSource(text, fromLanguage, to),\r\n    (to) => {\r\n        console.log(`Successfully generated ${to} translations.`)\r\n        return true\r\n    },\r\n    (error) => {\r\n        console.error(\"Error during translation:\", error)\r\n        return false\r\n    },\r\n)\r\n```","readmeFilename":"README.md"}