Skip to content

Commit 0157cd1

Browse files
committed
docs: add guidance on handling different scripts, dialects, and variants in translations https://web.tracklify.com/project/2b7ZVgE5/AdminForth/1271/0SNvyTuu/allow-to-select-languages-for-
1 parent 0f17b50 commit 0157cd1

File tree

1 file changed

+65
-0
lines changed
  • adminforth/documentation/docs/tutorial/08-Plugins

1 file changed

+65
-0
lines changed

adminforth/documentation/docs/tutorial/08-Plugins/10-i18n.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,71 @@ import { admin } from '../index';
572572
}
573573
```
574574
575+
## Different scripts (writing systems) / regions / variants / dialects
576+
577+
### Scripts (Writing systems)
578+
579+
For some languages you may want translations in a specific, non-default script (or want the choice to be deterministic).
580+
581+
For example, Serbian (`sr`) is written in both Cyrillic and Latin scripts. If you use only `sr`, an LLM may pick a script inconsistently (or default to Cyrillic). To force a particular script, use `translateLangAsBCP47Code`:
582+
583+
```ts
584+
translateLangAsBCP47Code: { sr: 'sr-Latn' }
585+
```
586+
587+
Alternatively, you can or course use the script-tagged BCP47 code directly in `supportedLanguages`:
588+
589+
```diff
590+
--- supportedLanguages: ['en', 'sr']
591+
+++ supportedLanguages: ['en', 'sr-Latn']
592+
```
593+
594+
However, in this case `sr-Latn` becomes the language identifier everywhere. For example if you expose language codes to an external app (e.g., in URLs or subdomains), you may end up with URLs like `https://my.site/sr-Latn/my-page`, which is sometimes undesirable. You can work around this by remapping `sr-Latn ↔ sr` in the external system, but we generally recommend `translateLangAsBCP47Code` as the dedicated, internal way to keep a clean ISO 639-1 code while translating as a specific BCP47 tag.
595+
596+
If you want to support both scripts explicitly, include both in `supportedLanguages`:
597+
598+
```ts
599+
supportedLanguages: ['en', 'sr-Latn', 'sr-Cyrl']
600+
```
601+
602+
### Dialects and national standards
603+
604+
European Portuguese and Brazilian Portuguese differ, so it’s common to use BCP47 region subtags to distinguish them.
605+
606+
To support both:
607+
608+
```ts
609+
supportedLanguages: ['en', 'pt-BR', 'pt-PT']
610+
```
611+
612+
If you only want one version (e.g. Brazilian Portuguese) but still want to keep a clean `pt` code in your API/URLs, use `translateLangAsBCP47Code`:
613+
614+
```ts
615+
supportedLanguages: ['en', 'pt']
616+
translateLangAsBCP47Code: { pt: 'pt-BR' }
617+
```
618+
619+
LLM adapters generally understand the BCP47 tags you provide.
620+
621+
### Variants
622+
623+
More rarely, you may need a specific language variant. For example, British English typically uses standard BrE spelling, but the Oxford English Dictionary variant (OED) differs in some cases:
624+
625+
| Standard BrE | Oxford (OED) |
626+
| --- | --- |
627+
| colour | colour |
628+
| organise | organize |
629+
| realise | realize |
630+
631+
You can use `translateLangAsBCP47Code` to request a specific variant:
632+
633+
```ts
634+
supportedLanguages: ['en']
635+
translateLangAsBCP47Code: { en: 'en-GB-oed' }
636+
```
637+
638+
As any BCP47 tag it is also supported in `supportedLanguages` directly, but again this will make the full tag (e.g., `en-GB-oed`) appear in your API/URLs external systems unless you remap it externally.
639+
575640
## Translating external application
576641
577642
You can use this module not only to translate admin area of your application but also to translate other parts like SEO-facing or user-facing services.

0 commit comments

Comments
 (0)