From a0c6bf0102440d7730238451b6dd45c29cdf52c5 Mon Sep 17 00:00:00 2001 From: jy95 Date: Wed, 24 Apr 2024 23:13:56 +0200 Subject: [PATCH 1/3] docs: faq --- documentation/docs/custom/i18nConfig.mdx | 4 +++- documentation/docs/faq.mdx | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/documentation/docs/custom/i18nConfig.mdx b/documentation/docs/custom/i18nConfig.mdx index 0f762b33..a632220c 100644 --- a/documentation/docs/custom/i18nConfig.mdx +++ b/documentation/docs/custom/i18nConfig.mdx @@ -33,7 +33,9 @@ import SingleDosageToText from "@site/src/components/single_dosage_to_text"; backendOptions: [{ projectId: 'myLocizeProjectId' }, { - loadPath: '/locales/{{lng}}/{{ns}}.json' // http api load path for my own fallback + // http api load path for my own fallback + // Check https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales/en for more info + loadPath: '/locales/{{lng}}/{{ns}}.json' }], // cacheHitMode: 'none' // (default) // cacheHitMode: 'refresh' // tries to refresh the cache by loading from the next backend and updates the cache diff --git a/documentation/docs/faq.mdx b/documentation/docs/faq.mdx index 6c524a4c..979a7f44 100644 --- a/documentation/docs/faq.mdx +++ b/documentation/docs/faq.mdx @@ -46,8 +46,24 @@ You can migrate your dosages from R3 to R4 quick easily, as it is just a matter
-How to support my own language ? +How can I customize or add my own language ? -Simply make a pull request on the repository. You can use [English files](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales/en) for reference. +You can choose your preferred way : + +1. Make a pull request on the repository : simply add translations files [for your locale](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales). +2. Use a [i18next backend](https://www.i18next.com/overview/plugins-and-utils#backends) like [showcast in documentation](demo/custom/i18nConfig) + +You can use [English files](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales/en) for reference.
+ +
+Which languages are currently built-in ? + +4 [locales](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales) are currently implemented : +1. "en" (English) +2. "fr" (French) +3. "nl" (Dutch) +4. "de" (German) + +
\ No newline at end of file From 8794100f43feb4ffca6a7fbe6598d824745e3e16 Mon Sep 17 00:00:00 2001 From: jy95 Date: Thu, 25 Apr 2024 11:38:10 +0200 Subject: [PATCH 2/3] feat: allow any BCP 47 language code recommended by i18next --- documentation/docs/faq.mdx | 5 +++-- src/api.ts | 3 +-- src/classes/Configurator.ts | 3 +-- src/types.ts | 30 ++++-------------------------- 4 files changed, 9 insertions(+), 32 deletions(-) diff --git a/documentation/docs/faq.mdx b/documentation/docs/faq.mdx index 979a7f44..f407dfb8 100644 --- a/documentation/docs/faq.mdx +++ b/documentation/docs/faq.mdx @@ -60,10 +60,11 @@ You can use [English files](https://github.com/jy95/fhir-dosage-utils/tree/main/
Which languages are currently built-in ? -4 [locales](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales) are currently implemented : +4 [locales](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales) are currently implemented : + 1. "en" (English) 2. "fr" (French) 3. "nl" (Dutch) 4. "de" (German) -
\ No newline at end of file + diff --git a/src/api.ts b/src/api.ts index 8f6f8a87..6bc45e87 100644 --- a/src/api.ts +++ b/src/api.ts @@ -11,7 +11,6 @@ import type { Dosage, DisplayOrder, I18InitOptions, - Language, NamespacesLocale, } from "./types"; @@ -22,7 +21,7 @@ const defaultI18NConfig: I18InitOptions = { backends: [ resourcesToBackend( // have to cast the function to be webpack / builder friendly - async (lng: Language, ns: NamespacesLocale) => + async (lng: string, ns: NamespacesLocale) => import(`./locales/${lng}/${ns}.json`), ), ], diff --git a/src/classes/Configurator.ts b/src/classes/Configurator.ts index 080dea96..82f4e504 100644 --- a/src/classes/Configurator.ts +++ b/src/classes/Configurator.ts @@ -9,7 +9,6 @@ import type { Config, DisplayOrder, I18N, - Language, Params, InitOptions, I18InitOptions, @@ -58,7 +57,7 @@ export class Configurator { /** * To change language */ - async changeLanguage(lng: Language) { + async changeLanguage(lng: string) { this.config = { ...this.config, language: lng, diff --git a/src/types.ts b/src/types.ts index 8a4c851c..fc9a7723 100644 --- a/src/types.ts +++ b/src/types.ts @@ -39,30 +39,6 @@ export type DoseAndRate = DoseAndRateR4 | DoseAndRateR5; export type { FromFHIRQuantityUnitToStringFct, FromCodeableConceptToStringFct }; -/** - * Represents supported languages. - */ -enum LanguageEnum { - /** - * English - */ - en = "en", - /** - * French - */ - fr = "fr", - /** - * Dutch - */ - nl = "nl", - /** - * German - */ - de = "de", -} - -export type Language = keyof typeof LanguageEnum; - /** * Represents the available display orders */ @@ -196,10 +172,12 @@ export type NamespacesLocale = // Parameters export interface Params { /** - * To set up the language + * BCP 47 language code to setup the library with * @defaultValue "en" (English) + * @see [FAQ](https://jy95.github.io/fhir-dosage-utils/docs/faq) for the built-in languages + * @see [I18next documentation](https://www.i18next.com/how-to/faq#how-should-the-language-codes-be-formatted) for the reasons behind BCP 47 */ - language?: Language; + language?: string; /** * Function to turn a quantity unit (e.g UCUM "ml") into a string for humans (e.g "militier") * The choice to handle plural form or not is thus under the hands of people ;) From 27a4122772488b8c165785483c23a38907fc0260 Mon Sep 17 00:00:00 2001 From: jy95 Date: Thu, 25 Apr 2024 11:49:44 +0200 Subject: [PATCH 3/3] docs: fix link --- documentation/docs/faq.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/docs/faq.mdx b/documentation/docs/faq.mdx index f407dfb8..16d55635 100644 --- a/documentation/docs/faq.mdx +++ b/documentation/docs/faq.mdx @@ -51,7 +51,7 @@ You can migrate your dosages from R3 to R4 quick easily, as it is just a matter You can choose your preferred way : 1. Make a pull request on the repository : simply add translations files [for your locale](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales). -2. Use a [i18next backend](https://www.i18next.com/overview/plugins-and-utils#backends) like [showcast in documentation](demo/custom/i18nConfig) +2. Use a [i18next backend](https://www.i18next.com/overview/plugins-and-utils#backends) like [showcast in documentation](custom/i18nConfig) You can use [English files](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales/en) for reference.