Add prefix for locale files when build
This commit is contained in:
parent
eeb1ace01d
commit
a30f0c7c64
@ -84,6 +84,19 @@ function dateFormat(fmt, date) {
|
||||
return fmt;
|
||||
}
|
||||
|
||||
function addAddonRefToFlt(fltContent) {
|
||||
const lines = fltContent.split("\n");
|
||||
const prefixedLines = lines.map((line) => {
|
||||
if (line.match(/^(?<message>[a-zA-Z]\S*)([ ]*=[ ]*)(?<pattern>.*)$/gm)) {
|
||||
// https://regex101.com/r/lQ9x5p/1
|
||||
return `${config.addonRef}-${line}`;
|
||||
} else {
|
||||
return line;
|
||||
}
|
||||
});
|
||||
return prefixedLines.join("\n");
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const t = new Date();
|
||||
const buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
|
||||
@ -121,7 +134,6 @@ async function main() {
|
||||
/__buildVersion__/g,
|
||||
/__buildTime__/g,
|
||||
];
|
||||
|
||||
const replaceTo = [author, description, homepage, version, buildTime];
|
||||
|
||||
replaceFrom.push(
|
||||
@ -129,6 +141,9 @@ async function main() {
|
||||
);
|
||||
replaceTo.push(...Object.values(config));
|
||||
|
||||
replaceFrom.push(/(data-l10n-id=")(.*")/gm);
|
||||
replaceTo.push(`$1${config.addonRef}-$2`);
|
||||
|
||||
const optionsAddon = {
|
||||
files: [
|
||||
join(buildDir, "**/*.xhtml"),
|
||||
@ -144,11 +159,18 @@ async function main() {
|
||||
};
|
||||
|
||||
const replaceResult = sync(optionsAddon);
|
||||
|
||||
const replaceResultFlt = sync({
|
||||
files: [join(buildDir, "addon/**/*.ftl")],
|
||||
processor: [addAddonRefToFlt],
|
||||
});
|
||||
|
||||
console.log(
|
||||
"[Build] Run replace in ",
|
||||
replaceResult
|
||||
.filter((f) => f.hasChanged)
|
||||
.map((f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`)
|
||||
.map((f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`),
|
||||
replaceResultFlt.filter((f) => f.hasChanged).map((f) => `${f.file} : OK`)
|
||||
);
|
||||
|
||||
console.log("[Build] Replace OK");
|
||||
|
@ -63,16 +63,17 @@ function _getString(
|
||||
localString: string,
|
||||
options: { branch?: string | undefined; args?: Record<string, unknown> } = {}
|
||||
): string {
|
||||
const localStringWithPrefix = `${config.addonRef}-${localString}`;
|
||||
const { branch, args } = options;
|
||||
const pattern = addon.data.locale?.current.formatMessagesSync([
|
||||
{ id: localString, args },
|
||||
{ id: localStringWithPrefix, args },
|
||||
])[0];
|
||||
if (!pattern) {
|
||||
return localString;
|
||||
return localStringWithPrefix;
|
||||
}
|
||||
if (branch && pattern.attributes) {
|
||||
return pattern.attributes[branch] || localString;
|
||||
return pattern.attributes[branch] || localStringWithPrefix;
|
||||
} else {
|
||||
return pattern.value || localString;
|
||||
return pattern.value || localStringWithPrefix;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user