Skip to content

Commit

Permalink
Merge pull request #41 from jy95/improvements
Browse files Browse the repository at this point in the history
feat: allow any BCP 47 language code recommended by i18next
  • Loading branch information
jy95 authored Apr 25, 2024
2 parents 438abe3 + 27a4122 commit 521ac91
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
4 changes: 3 additions & 1 deletion documentation/docs/custom/i18nConfig.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions documentation/docs/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,25 @@ You can migrate your dosages from R3 to R4 quick easily, as it is just a matter
</details>

<details>
<summary>How to support my own language ?</summary>
<summary>How can I customize or add my own language ?</summary>

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](custom/i18nConfig)

You can use [English files](https://github.com/jy95/fhir-dosage-utils/tree/main/src/locales/en) for reference.

</details>

<details>
<summary>Which languages are currently built-in ?</summary>

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)

</details>
3 changes: 1 addition & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
Dosage,
DisplayOrder,
I18InitOptions,
Language,
NamespacesLocale,
} from "./types";

Expand All @@ -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`),
),
],
Expand Down
3 changes: 1 addition & 2 deletions src/classes/Configurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
Config,
DisplayOrder,
I18N,
Language,
Params,
InitOptions,
I18InitOptions,
Expand Down Expand Up @@ -58,7 +57,7 @@ export class Configurator {
/**
* To change language
*/
async changeLanguage(lng: Language) {
async changeLanguage(lng: string) {
this.config = {
...this.config,
language: lng,
Expand Down
30 changes: 4 additions & 26 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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 ;)
Expand Down

0 comments on commit 521ac91

Please sign in to comment.