teach the locale system that sometimes braces are just braces

This commit is contained in:
dakkar 2024-06-12 15:06:01 +01:00
parent d53df1c5d2
commit f7898fa89d
5 changed files with 13 additions and 6 deletions

View file

@ -754,7 +754,7 @@ alwaysMarkSensitive: "Mark as sensitive by default"
loadRawImages: "Load original images instead of showing thumbnails" loadRawImages: "Load original images instead of showing thumbnails"
searchEngine: "Search Engine For Search MFM" searchEngine: "Search Engine For Search MFM"
searchEngineOther: "Other" searchEngineOther: "Other"
searchEngineCustomURIDescription: "The custom URI must be input in the format like \"https://www.google.com/search?q={query}\" or \"https://www.google.com/search?q=%s\"." searchEngineCustomURIDescription: "The custom URI must be input in the format like \"https://www.google.com/search?q=\\{query}\" or \"https://www.google.com/search?q=%s\"."
searchEngineCusomURI: "Custom URI" searchEngineCusomURI: "Custom URI"
disableShowingAnimatedImages: "Don't play animated images" disableShowingAnimatedImages: "Don't play animated images"
highlightSensitiveMedia: "Highlight sensitive media" highlightSensitiveMedia: "Highlight sensitive media"

View file

@ -6,7 +6,10 @@ import ts from 'typescript';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
const parameterRegExp = /\{(\w+)\}/g; // braces preceded by backslashes are literal, they don't represent
// parameters; they get cleaned up by `locales/index.js` before
// getting shipped to the browser
const parameterRegExp = /(?<!\\)\{(\w+)\}/g;
function createMemberType(item) { function createMemberType(item) {
if (typeof item !== 'string') { if (typeof item !== 'string') {

4
locales/index.d.ts vendored
View file

@ -3029,9 +3029,9 @@ export interface Locale extends ILocale {
*/ */
"searchEngineOther": string; "searchEngineOther": string;
/** /**
* URI "https://www.google.com/search?q={query}" "https://www.google.com/search?q=%s" * URI "https://www.google.com/search?q=\{query}" "https://www.google.com/search?q=%s"
*/ */
"searchEngineCustomURIDescription": ParameterizedString<"query">; "searchEngineCustomURIDescription": string;
/** /**
* URI * URI
*/ */

View file

@ -49,7 +49,11 @@ const primaries = {
}; };
// 何故か文字列にバックスペース文字が混入することがあり、YAMLが壊れるので取り除く // 何故か文字列にバックスペース文字が混入することがあり、YAMLが壊れるので取り除く
const clean = (text) => text.replace(new RegExp(String.fromCodePoint(0x08), 'g'), ''); //
// also, we remove the backslashes in front of open braces (the
// backslashes are only needed to tell `generateDTS.js` that the
// braces do not represent parameters)
const clean = (text) => text.replace(new RegExp(String.fromCodePoint(0x08), 'g'), '').replaceAll(new RegExp(/\\+\{/,'g'), '{');
export function build() { export function build() {
const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(new URL(`${c}.yml`, import.meta.url), 'utf-8'))) || {}, a), {}); const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(new URL(`${c}.yml`, import.meta.url), 'utf-8'))) || {}, a), {});

View file

@ -753,7 +753,7 @@ alwaysMarkSensitive: "デフォルトでメディアをセンシティブ設定
loadRawImages: "添付画像のサムネイルをオリジナル画質にする" loadRawImages: "添付画像のサムネイルをオリジナル画質にする"
searchEngine: "検索MFMの検索エンジン" searchEngine: "検索MFMの検索エンジン"
searchEngineOther: "他" searchEngineOther: "他"
searchEngineCustomURIDescription: "カスタム URI は、\"https://www.google.com/search?q={query}\" や \"https://www.google.com/search?q=%s\" のような形式で入力する必要があります。" searchEngineCustomURIDescription: "カスタム URI は、\"https://www.google.com/search?q=\\{query}\" や \"https://www.google.com/search?q=%s\" のような形式で入力する必要があります。"
searchEngineCusomURI: "カスタム URI" searchEngineCusomURI: "カスタム URI"
disableShowingAnimatedImages: "アニメーション画像を再生しない" disableShowingAnimatedImages: "アニメーション画像を再生しない"
highlightSensitiveMedia: "メディアがセンシティブであることを分かりやすく表示" highlightSensitiveMedia: "メディアがセンシティブであることを分かりやすく表示"