Skip to content

Commit

Permalink
✨ feat: Build localazy locales enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
elisiondan committed Aug 4, 2023
1 parent e1fbac7 commit 3439f7b
Show file tree
Hide file tree
Showing 6 changed files with 1,519 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"build": "rimraf lib/* && npm run generate-types && npm run build:main && npm run build:module",
"build": "rimraf lib/* && npm run build-scripts && npm run build:main && npm run build:module",
"build:main": "tsc -p tsconfig.build.json",
"build:module": "tsc -p tsconfig.module.json",
"lint": "eslint . --ext .ts",
Expand All @@ -15,7 +15,7 @@
"minor": "standard-version --release-as minor",
"major": "standard-version --release-as major",
"release": "git push && git push --tags",
"generate-types": "npx ts-node --esm ./scripts/build-translations-index.ts",
"build-scripts": "npx ts-node --esm ./scripts/build/index.ts",
"upload-translations": "npx ts-node --esm ./scripts/localazy.ts -- --upload",
"download-translations": "npx ts-node --esm ./scripts/localazy.ts -- --download"
},
Expand Down
26 changes: 26 additions & 0 deletions scripts/build/build-locales-enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import fse from 'fs-extra'
import { getLocalazyLanguages } from '../../src';

async function buildLocalesEnum() {
let content = "export enum Locales {\n";
getLocalazyLanguages().forEach((language, index) => {
const sanitizedLanguage = language.name
.replace(/&/g, "and")
.replace(/[)(,.]/g, "")
.replace(/[\s]/g, '_')
.replace(/[-#’']/g, '_')
.toUpperCase();
content += `\t${sanitizedLanguage} = "${language.locale}"`;
if (index !== getLocalazyLanguages().length - 1) {
content += ",\n";
} else {
content += "\n";
}
});

content += "}\n";

fse.writeFileSync('./src/locales.ts', content)
}

buildLocalesEnum();
File renamed without changes.
2 changes: 2 additions & 0 deletions scripts/build/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./build-locales-enum";
import "./build-translations-index";
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export type { Language } from "./language";
export { getLocalazyLanguages } from "./localazy-languages";
export * from "./localazy-languages";
import "./translations";
Loading

0 comments on commit 3439f7b

Please sign in to comment.