Skip to content

Commit bfac3e8

Browse files
committed
Replace old runtime code generation with new static lit-localize library
1 parent e3bfd9b commit bfac3e8

Some content is hidden

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

43 files changed

+56
-960
lines changed

config.schema.json

+1-24
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

-11
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)