intl-schematic
Advanced tools
| { | ||
| "type": "string", | ||
| "title": "Plain string translation" | ||
| } |
+3
-1
| { | ||
| "name": "intl-schematic", | ||
| "version": "1.0.0-rc.3", | ||
| "version": "1.0.0-rc.4", | ||
| "license": "MIT", | ||
@@ -12,2 +12,4 @@ "repository": { | ||
| "types": "src/index", | ||
| "esnext": "src/index", | ||
| "sideEffects": false, | ||
| "scripts": { | ||
@@ -14,0 +16,0 @@ "build:schema": "node ./generate-schema.js", |
+60
-2
@@ -19,3 +19,3 @@ <h1 align="center"> | ||
| - π **Pluginable**: extend any processing step without limits - see the [plugins API](/packages/plugins/) for more; | ||
| - π **JSON-validation using a JSON-schema**: intellisense and popup hints right in the translation document; | ||
| - π **JSON-validation using a [JSON-schema](#using-with-json-schema)**: intellisense and popup hints right in the translation document; | ||
| - π« **No string-interpolation**: translation strings will never be processed or mangled by-default, so all unicode symbols are safe to use; | ||
@@ -34,2 +34,3 @@ | ||
| - [Add default plugins and processors](#add-default-plugins-and-processors) | ||
| - [Using with JSON-schema](#using-with-json-schema) | ||
@@ -142,3 +143,3 @@ | ||
| Translating keys relies on simple key-value lookup, and most libraries | ||
| Translating keys relies on simple key-value lookup, and most i18n libraries | ||
| add many unnecessary features on top of this primitive functionality. | ||
@@ -208,1 +209,58 @@ | ||
| ``` | ||
| ## Using with JSON-schema | ||
| `intl-schematic`, as well as its plugins, defines a JSON-schema API designed specifically to allow type-checking JSON translation documents. | ||
| To define a JSON-schema for your translation documents, simply create a `.schema.json` file with this template: | ||
| ```json | ||
| // translation.schema.json | ||
| { | ||
| "$ref": "./node_modules/intl-schematic/translation.schema.json", | ||
| "additionalProperties": { | ||
| "anyOf": [ | ||
| // Definition for the default string key-value pair | ||
| { | ||
| "$ref": "./node_modules/intl-schematic/property.schema.json", | ||
| } | ||
| // Add references to more allowed types for your schema | ||
| /* for example, @intl-schematic/plugin-processors definition: | ||
| { | ||
| "$ref": "./node_modules/@intl-schematic/plugin-processors/property.schema.json" | ||
| } | ||
| */ | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
| And then use it in your translation document: | ||
| ```json | ||
| // en.json | ||
| { | ||
| // Path to the schema from the example above | ||
| "$schema": "./translation.schema.json", | ||
| "key": "Translation" | ||
| } | ||
| ``` | ||
| ```js | ||
| import translation from './en.json'; | ||
| const t = createTranslator(() => translation); | ||
| // Etc., see example at the start of this file | ||
| ``` | ||
| > Note: the `$schema` key will be automatically excluded\ | ||
| > from type hints for `t()` for your convenience! | ||
| ### Plugins that define a `property.schema.json` | ||
| Not all plugins have a `property.schema.json` file, not all of them need to.\ | ||
| Here's a list of the ones that do: | ||
| - [`@intl-schematic/plugin-arrays`](/packages/plugins/arrays/) (included in **defaults**) | ||
| - use arrays to cross-reference keys and define complex multiline texts | ||
| - [`@intl-schematic/plugin-processors`](/packages/plugins/processors/) (included in **defaults**) | ||
| - apply custom and default processors to format the user inputs |
| { | ||
| "type": "object", | ||
| "title": "Translation document", | ||
| "description": "Contains various localized strings that can be accessed with a key" | ||
| "description": "Contains various localized strings that can be accessed with a key", | ||
| "properties": { | ||
| "$schema": { | ||
| "type": "string", | ||
| "title": "Reference to the translation document schema definition" | ||
| } | ||
| } | ||
| } |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
34601
6.78%14
7.69%553
1.84%263
28.29%