Skip to content

Commit bec25bd

Browse files
authored
Merge pull request #44 from PolymerLabs/new-runtime
Replace runtime code generation with static lit-localize library
2 parents 10d02c1 + 421cc2d commit bec25bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+61
-966
lines changed

CHANGELOG.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- [BREAKING] The `tsOut` parameter is replaced by the new `output` object with
1111
`mode: "runtime"|"transform"`.
1212

13+
- [BREAKING] Runtime mode no longer emits a `localization.ts` module. Instead,
14+
users should always import from the `lit-localize` module and use
15+
`configureLocalization`, `msg`, and other functions. See the README details of
16+
this new API.
17+
1318
- Add `transform` output mode, which emits an entire copy of the program in each
1419
locale, where all `msg` calls have been replaced with the raw translated
1520
template for that locale.
1621

17-
- Add ability to generate a `setLocale` function by setting
18-
`output.exportSetLocaleFunction: true`.
19-
20-
- Add ability to customize how locale is initialized from the URL through
21-
the `regexp` and `param` properties of the `output.setLocaleFromUrl` object.
22-
2322
- Fix incorrect JSON schema error about `targetLocales` field not being a
2423
`string[]`.
2524

config.schema.json

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,15 @@
2525
"additionalProperties": false,
2626
"description": "Configuration specific to the `runtime` output mode.",
2727
"properties": {
28-
"defaultLocale": {
29-
"description": "The initial locale, if no other explicit locale selection has been made.\nDefaults to the value of `sourceLocale`.",
30-
"type": "string"
31-
},
32-
"exportSetLocaleFunction": {
33-
"description": "If true, export a `setLocale(locale: Locale)` function in the generated\n`<outputDir>/localization.ts` module. Defaults to false.\n\nNote that calling this function will set the locale for subsequent calls to\n`msg`, but will not automatically re-render existing templates.",
34-
"type": "boolean"
35-
},
3628
"mode": {
3729
"enum": [
3830
"runtime"
3931
],
4032
"type": "string"
4133
},
4234
"outputDir": {
43-
"description": "Output directory for generated TypeScript modules. After running\nlit-localize, this directory will contain:\n\n1. localization.ts -- A TypeScript module that exports the `msg` function,\n along with other utilities.\n\n2. <locale>.ts -- For each `targetLocale`, a TypeScript module that exports\n the translations in that locale keyed by message ID. These modules are\n used automatically by localization.ts and should not typically be\n imported directly by user code.",
35+
"description": "Output directory for generated TypeScript modules. Into this directory will\nbe generated a <locale>.ts for each `targetLocale`, each a TypeScript\nmodule that exports the translations in that locale keyed by message ID.",
4436
"type": "string"
45-
},
46-
"setLocaleFromUrl": {
47-
"additionalProperties": false,
48-
"description": "Automatically set the locale based on the URL at application startup.",
49-
"properties": {
50-
"param": {
51-
"description": "Set locale based on the value of a URL query parameter.\n\nFinds the first matching query parameter from `window.location.search`.\nIf no such URL query parameter is set, or if it is not a valid locale\ncode, then `defaultLocale` is used.\n\nIt is an error to set both `regexp` and `param`.\n\nExamples:\n\n1. \"lang\"\n\n https://example.com?foo&lang=es&bar\n ^^",
52-
"type": "string"
53-
},
54-
"regexp": {
55-
"description": "Set locale based on matching a regular expression against the URL.\n\nThe regexp will be matched against `window.location.href`, and the first\ncapturing group will be used as the locale. If no match is found, or if\nthe capturing group does not contain a valid locale code, then\n`defaultLocale` is used.\n\nOptionally use the special string `:LOCALE:` to substitute a capturing\ngroup into the regexp that will only match the currently configured\nlocale codes (`sourceLocale` and `targetLocales`). For example, if\nsourceLocale=en and targetLocales=es,zh_CN, then the regexp\n\"^https?://:LOCALE:\\\\.\" becomes \"^https?://(en|es|zh_CN)\\\\.\".\n\nTips: Remember to double-escape literal backslashes (once for JSON, once\nfor the regexp), and note that you can use `(?:foo)` to create a\nnon-capturing group.\n\nIt is an error to set both `regexp` and `param`.\n\nExamples:\n\n1. \"^https?://[^/]+/:LOCALE:(?:$|[/?#])\"\n\n Set locale from the first path component.\n\n E.g. https://www.example.com/es/foo\n ^^\n\n2. \"^https?://:LOCALE:\\\\.\"\n\n Set locale from the first subdomain.\n\n E.g. https://es.example.com/foo\n ^^",
56-
"type": "string"
57-
}
58-
},
59-
"type": "object"
6037
}
6138
},
6239
"required": [

src/config.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,6 @@ export function readConfigFileAndWriteSchema(configPath: string): Config {
136136
}
137137

138138
const validated = parsed as ConfigFile;
139-
const output = validated.output;
140-
if (output.mode === 'runtime' && output.setLocaleFromUrl) {
141-
if (!!output.setLocaleFromUrl.param === !!output.setLocaleFromUrl.regexp) {
142-
throw new KnownError(
143-
`Error validating config file ${configPath}:\n\n` +
144-
`If output.setLocaleFromUrl is set, then either param or regexp ` +
145-
`must be set, but not both.`
146-
);
147-
}
148-
}
149-
150139
writeConfigSchemaIfMissing(validated, configPath);
151140

152141
const baseDir = pathLib.dirname(configPath);

0 commit comments

Comments
 (0)