https://github.com/Divine-Software/divine-companions/tree/master/localization Skip to content Sign up * Product + Features + Mobile + Actions + Codespaces + Copilot + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Skills + GitHub Sponsors + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} Divine-Software / divine-companions Public * Notifications * Fork 0 * Star 2 * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags divine-companions/localization/ Go to file divine-companions/localization/ Latest commit @LeviticusMB LeviticusMB RELEASING: Releasing 1 package(s) ... a0b7d28 Jul 5, 2022 RELEASING: Releasing 1 package(s) Releases: @divine/localization@0.1.2 a0b7d28 Git stats * History Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time . . src Secondary translated language may be null/undefined. Jul 5, 2022 test Secondary translated language may be null/undefined. Jul 5, 2022 CHANGELOG.md RELEASING: Releasing 1 package(s) Jul 5, 2022 Makefile Initial version of @divine/localization, The Divine Localization Libr... Jul 2, 2022 README.md Secondary translated language may be null/undefined. Jul 5, 2022 package.json RELEASING: Releasing 1 package(s) Jul 5, 2022 tsconfig.json Initial version of @divine/localization, The Divine Localization Libr... Jul 2, 2022 The Divine Localization Library The Doctrine The Motivation The Conviction README.md The Divine Localization Library The Doctrine Localization and translations should be code, not data. The Motivation As developers, we want our languages to be expressive, elegant and concise, so that we may express complex thoughts effortlessly and clearly to both the machine and readers of our code. We want first-class editor support for syntax highlighting, code completions and validation. Yet, when it comes to building something as complex as natural language sentences, we are supposed to make do with just plain strings, a switch/case construct and some fixed plural function like it's still the 80's. No typed arguments, no syntax validation or highlighting, no lookup-tables, custom functions or dictionaries, no tooling for finding out where a particular translation is used by the program, or if it's even used at all. Additionally, in web applications in particular, you may sometimes want to translate rich-text/markup and not just plain text. No can do. So now the application has to know if a particular sentence should be HTML-encoded or not, with no way to enforce that all translations match -- and prepare to get p0wned if you forget to encode a parameter. The Conviction This TypeScript library is really more dogma than code. In fact, it currently only exposes a single function! However: * Your translations are easily available for consumption as a single property, either as a constant or a function. * Translation keys can be plain strings, JSX/TSX markup (React/ Stencil/etc) or any other custom type or object you wish. * Your IDE will provide code completion and will show what arguments are required and syntax highlight the actual translations. * TypeScript will validate that all translations conform to the base language specification for every key, both regarding input parameters and the return type. * You can define and use any kind of utility functions or lookup tables/dictionaries in your translations, including the standard Intl namespace for formatting dates, numbers and lists. export const EN = { intro: { title: 'Introduction', about: (who: Person) => `About ${who.name}`, loves: (who: Person, what: Item, count: number) => <>The gentle {who.name} loves {EN_PRONOUNS[who.gender]} little {EN_PLURAL(what, count)}. }, } ... export const ES: Translation = { intro: { title: `Introduccion`, loves: ({ name, gender }, what, count) => <> {gender !== 'f' ? 'El buen' : 'La buena'} {name} ama {count === 1 ? 'su' : 'sus'} { ES_ADJ(ES_ITEMS[what].g, count, 'pequeno', 'pequena', 'pequenos', 'pequenas')} { ES_ITEMS[what][count === 1 ? 's' : 'p']} } } ... const { intro } = translated(EN, ES) as typeof EN; const html =

{ intro.title }

{ intro.about(params.who) }

{ intro.loves(params.who, params.what, params.count) }

Check out the fully interactive Playground example to better understand how it works. Make some mistakes and see what happens! Footer (c) 2022 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.