mirror of
https://github.com/home-assistant/frontend.git
synced 2025-10-18 16:19:46 +00:00

Co-authored-by: Bram Kragten <mail@bramkragten.nl> Co-authored-by: Paul Bottein <paul.bottein@gmail.com> Co-authored-by: Steve Repsher <steverep@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Joakim Sørensen <ludeeus@ludeeus.dev> Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: puddly <32534428+puddly@users.noreply.github.com> Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: Bagira <bagdi.istvan@gmail.com> Co-authored-by: Ben Randall <veleek@gmail.com> Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com> Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: Chris <31055115+darthsebulba04@users.noreply.github.com> Co-authored-by: Aaron Carson <aaron@aaroncarson.co.uk> Co-authored-by: David F. Mulcahey <david.mulcahey@me.com> Co-authored-by: Yosi Levy <37745463+yosilevy@users.noreply.github.com> Co-authored-by: Alex van den Hoogen <alex3305@gmail.com> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: Jani Lahti <jani.lahti@iki.fi> Co-authored-by: RoboMagus <68224306+RoboMagus@users.noreply.github.com> Co-authored-by: Brynley McDonald <brynley+github@zephire.nz> Co-authored-by: Denis Shulyaka <Shulyaka@gmail.com> Co-authored-by: KablammoNick <nick@kablammo.net> Co-authored-by: Allen Porter <allen@thebends.org> Co-authored-by: Philip Allgaier <mail@spacegaier.de>
73 lines
1.9 KiB
JavaScript
Executable File
73 lines
1.9 KiB
JavaScript
Executable File
const del = require("del");
|
|
const path = require("path");
|
|
const gulp = require("gulp");
|
|
const fs = require("fs");
|
|
const paths = require("../paths");
|
|
|
|
const outDir = "build/locale-data";
|
|
|
|
gulp.task("clean-locale-data", () => del([outDir]));
|
|
|
|
gulp.task("ensure-locale-data-build-dir", (done) => {
|
|
if (!fs.existsSync(outDir)) {
|
|
fs.mkdirSync(outDir, { recursive: true });
|
|
}
|
|
done();
|
|
});
|
|
|
|
const modules = {
|
|
"intl-relativetimeformat": "RelativeTimeFormat",
|
|
"intl-datetimeformat": "DateTimeFormat",
|
|
"intl-numberformat": "NumberFormat",
|
|
};
|
|
|
|
gulp.task("create-locale-data", (done) => {
|
|
const translationMeta = JSON.parse(
|
|
fs.readFileSync(
|
|
path.join(paths.translations_src, "translationMetadata.json")
|
|
)
|
|
);
|
|
Object.entries(modules).forEach(([module, className]) => {
|
|
Object.keys(translationMeta).forEach((lang) => {
|
|
try {
|
|
const localeData = String(
|
|
fs.readFileSync(
|
|
require.resolve(`@formatjs/${module}/locale-data/${lang}.js`)
|
|
)
|
|
)
|
|
.replace(
|
|
new RegExp(
|
|
`\\/\\*\\s*@generated\\s*\\*\\/\\s*\\/\\/\\s*prettier-ignore\\s*if\\s*\\(Intl\\.${className}\\s*&&\\s*typeof\\s*Intl\\.${className}\\.__addLocaleData\\s*===\\s*'function'\\)\\s*{\\s*Intl\\.${className}\\.__addLocaleData\\(`,
|
|
"im"
|
|
),
|
|
""
|
|
)
|
|
.replace(/\)\s*}/im, "");
|
|
// make sure we have valid JSON
|
|
JSON.parse(localeData);
|
|
if (!fs.existsSync(path.join(outDir, module))) {
|
|
fs.mkdirSync(path.join(outDir, module), { recursive: true });
|
|
}
|
|
fs.writeFileSync(
|
|
path.join(outDir, `${module}/${lang}.json`),
|
|
localeData
|
|
);
|
|
} catch (e) {
|
|
if (e.code !== "MODULE_NOT_FOUND") {
|
|
throw e;
|
|
}
|
|
}
|
|
});
|
|
done();
|
|
});
|
|
});
|
|
|
|
gulp.task(
|
|
"build-locale-data",
|
|
gulp.series(
|
|
"clean-locale-data",
|
|
"ensure-locale-data-build-dir",
|
|
"create-locale-data"
|
|
)
|
|
);
|