@authup/i18n 1.0.0-beta.69 → 1.0.0-beta.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +138 -0
  2. package/package.json +5 -5
package/README.md ADDED
@@ -0,0 +1,138 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/authup/authup/master/.github/assets/logo.svg" alt="Authup logo" width="96" height="96" />
3
+ </p>
4
+
5
+ <h1 align="center">@authup/i18n</h1>
6
+
7
+ <p align="center">
8
+ <b>Authup's translation catalogs in English, German, French and Spanish, ready for an ilingo store.</b><br>
9
+ The labels, error messages and mail copy the consoles and the server use, without a framework attached.
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://www.npmjs.com/package/@authup/i18n"><img src="https://img.shields.io/npm/v/@authup/i18n" alt="npm version" /></a>
14
+ <a href="https://github.com/authup/authup/actions/workflows/main.yml"><img src="https://github.com/authup/authup/actions/workflows/main.yml/badge.svg" alt="CI" /></a>
15
+ <a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue" alt="License: Apache-2.0" /></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="#installation"><b>Installation</b></a> · <a href="#usage">Usage</a> · <a href="#api">API</a> · <a href="https://authup.org">Documentation</a>
20
+ </p>
21
+
22
+ ---
23
+
24
+ ## Why @authup/i18n?
25
+
26
+ An application that embeds Authup's UI components, renders Authup's error codes or names its permissions needs the same words Authup uses, in the same languages. This package is those words as plain data: an [ilingo](https://github.com/tada5hi/ilingo) catalog tree you load into a store, plus the locale registry and the key enums.
27
+
28
+ | Concern | Without it | With it |
29
+ |---|---|---|
30
+ | **Error messages** | A message table for every `ErrorCode` you might receive | `authupError` namespace, keyed by the `ErrorCode` values of `@authup/errors` |
31
+ | **Permission and scope names** | Showing raw identifiers such as `user_update` | `authupPermission`, `authupScope` and `authupPolicy` give a display name per built-in identifier |
32
+ | **Locales** | A list of supported languages kept in step by hand | `LOCALES`, `isLocale` and `matchLocale` over the four authored locales |
33
+ | **Key drift** | A key missing in one language shows up at runtime | Every catalog is typed against its key enum, and a parity test checks all four locales |
34
+
35
+ ## Installation
36
+
37
+ ```shell
38
+ npm install @authup/i18n ilingo
39
+ ```
40
+
41
+ ESM only. Node.js `^22.13.0 || ^23.5.0 || >=24.0.0`. `ilingo` is a dependency of this package; install it yourself as well when your code builds the `Ilingo` instance. `@ebec/core` and `validup` are optional peers: they matter only for the typed `IssueDataByCode` augmentation this package declares.
42
+
43
+ ## Usage
44
+
45
+ ### Load the catalogs
46
+
47
+ ```typescript
48
+ import {
49
+ CATALOGS,
50
+ DEFAULT_LOCALE,
51
+ TranslatorTranslationMailKey,
52
+ TranslatorTranslationNamespace,
53
+ matchLocale,
54
+ } from '@authup/i18n';
55
+ import { ErrorCode } from '@authup/errors';
56
+ import { Ilingo, MemoryStore } from 'ilingo';
57
+
58
+ const ilingo = new Ilingo({
59
+ store: new MemoryStore({ data: CATALOGS }),
60
+ locale: DEFAULT_LOCALE,
61
+ });
62
+
63
+ const locale = matchLocale('de-DE') ?? DEFAULT_LOCALE; // 'de'
64
+
65
+ await ilingo.get({
66
+ namespace: TranslatorTranslationNamespace.ERROR,
67
+ key: ErrorCode.ENTITY_NOT_FOUND,
68
+ locale,
69
+ });
70
+
71
+ await ilingo.get({
72
+ namespace: TranslatorTranslationNamespace.MAIL,
73
+ key: TranslatorTranslationMailKey.PASSWORD_RESET_EXPIRY,
74
+ data: { minutes: 30 },
75
+ }); // 'The code expires in 30 minutes.'
76
+ ```
77
+
78
+ - `CATALOGS` is an ilingo `CatalogNode` (locale, then namespace, then translations), so `MemoryStore({ data: CATALOGS })` takes it as is and `getSync` works too.
79
+ - `matchLocale` lowercases the tag, keeps the primary subtag and returns it when it is an authored locale, else `undefined`.
80
+ - Values may carry `{{name}}` placeholders, filled from `data`.
81
+
82
+ ### Pick singular or plural
83
+
84
+ ```typescript
85
+ import { TranslatorTranslationEntityKey, TranslatorTranslationNamespace } from '@authup/i18n';
86
+ import type { Ilingo } from 'ilingo';
87
+
88
+ declare const ilingo: Ilingo;
89
+
90
+ await ilingo.get({
91
+ namespace: TranslatorTranslationNamespace.ENTITY,
92
+ key: TranslatorTranslationEntityKey.USER,
93
+ count: 1,
94
+ }); // 'User'
95
+ ```
96
+
97
+ Entity nouns are ilingo plural nodes: `count: 1` selects the singular, any other count the plural.
98
+
99
+ ## Namespaces
100
+
101
+ | Enum member | Namespace | Keys |
102
+ |---|---|---|
103
+ | `ENTITY` | `authupEntity` | `TranslatorTranslationEntityKey`, plural nouns |
104
+ | `FIELD` | `authupField` | `TranslatorTranslationFieldKey` |
105
+ | `ACTION` | `authupAction` | `TranslatorTranslationActionKey` |
106
+ | `COMMON` | `authupCommon` | `TranslatorTranslationCommonKey` |
107
+ | `CLIENT` | `authupClient` | `TranslatorTranslationClientKey` |
108
+ | `APP` | `authupApp` | `TranslatorTranslationAppKey` |
109
+ | `ERROR` | `authupError` | `ErrorCode` from `@authup/errors` |
110
+ | `MAIL` | `authupMail` | `TranslatorTranslationMailKey`, transactional mail copy |
111
+ | `PERMISSION` | `authupPermission` | `PermissionName` from `@authup/core-kit` |
112
+ | `SCOPE` | `authupScope` | `ScopeName` from `@authup/core-kit` |
113
+ | `POLICY` | `authupPolicy` | `SystemPolicyName` from `@authup/access` |
114
+ | `VUECS` | `vuecs` | `TranslatorTranslationVuecsKey`, overrides for `@vuecs/*` components |
115
+
116
+ ## API
117
+
118
+ | Export | Kind | Purpose |
119
+ |---|---|---|
120
+ | `CATALOGS` | const | Every authored locale and namespace, as an ilingo catalog node |
121
+ | `TranslatorTranslation<Namespace><Language>` | const | One namespace of one locale, e.g. `TranslatorTranslationErrorGerman` |
122
+ | `TranslatorTranslationNamespace` | enum | The namespace names above |
123
+ | `TranslatorTranslation<Namespace>Key` | enum | The key set of each authup-owned namespace |
124
+ | `LOCALES`, `LOCALE_CODES`, `DEFAULT_LOCALE` | const | `en`, `de`, `fr`, `es` with their native names; the default is `en` |
125
+ | `isLocale`, `matchLocale` | function | Narrow a string or a BCP-47 tag onto an authored locale |
126
+ | `LocaleCode`, `LocaleDescriptor`, `NamespaceTranslations`, `AuthupErrorData`, `SystemPolicyNameValue` | type | Locale, catalog and error-data types |
127
+
128
+ ## Notes
129
+
130
+ - **Policy names contain dots.** `system.default` is a path to ilingo, so escape the dots when you look one up: `key: 'system\\.default'`.
131
+ - **The namespaces are prefixed with `authup`** so they cannot collide with a host application's own catalogs. Only `vuecs` is not, because it overrides the `@vuecs/*` components' own namespace.
132
+ - **Every catalog is loaded eagerly.** All four locales are in `CATALOGS`; there is no lazy loading per locale yet.
133
+
134
+ ## License
135
+
136
+ Made with 💚
137
+
138
+ Published under the [Apache 2.0 License](./LICENSE).
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@authup/i18n",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.69",
5
- "description": "Framework-agnostic translation catalogs and locale registry.",
4
+ "version": "1.0.0-beta.71",
5
+ "description": "Authup's translation catalogs in English, German, French and Spanish, ready for an ilingo store.",
6
6
  "license": "Apache-2.0",
7
7
  "exports": {
8
8
  "./package.json": "./package.json",
@@ -50,9 +50,9 @@
50
50
  },
51
51
  "homepage": "https://github.com/authup/authup#readme",
52
52
  "dependencies": {
53
- "@authup/access": "^1.0.0-beta.69",
54
- "@authup/core-kit": "^1.0.0-beta.69",
55
- "@authup/errors": "^1.0.0-beta.69",
53
+ "@authup/access": "^1.0.0-beta.71",
54
+ "@authup/core-kit": "^1.0.0-beta.71",
55
+ "@authup/errors": "^1.0.0-beta.71",
56
56
  "ilingo": "^6.2.0"
57
57
  },
58
58
  "devDependencies": {