Skip to content

Commit

Permalink
mobile: i18n (#1220)
Browse files Browse the repository at this point in the history
i18n
  • Loading branch information
kayleegeorge authored Jul 26, 2024
1 parent 062a4c2 commit e853bb3
Show file tree
Hide file tree
Showing 74 changed files with 2,317 additions and 455 deletions.
2 changes: 1 addition & 1 deletion apps/daimo-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"expo-image": "^1.10.6",
"expo-linking": "~6.2.2",
"expo-local-authentication": "~13.8.0",
"expo-localization": "~14.8.3",
"expo-localization": "^14.8.4",
"expo-notifications": "~0.27.6",
"expo-splash-screen": "~0.26.4",
"expo-status-bar": "~1.11.1",
Expand Down
52 changes: 52 additions & 0 deletions apps/daimo-mobile/src/i18n/generate/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import fs from "fs";
import path from "path";

import { en } from "../languages/en";

// TODO: add this to package.json generation
function generateLanguageType(json: any, parentKey: string = ""): string {
let type = "";

for (const [key, value] of Object.entries(json)) {
const fullKey = parentKey ? `${parentKey}.${key}` : key;

if (typeof value === "function") {
const funcStr = value.toString();
const params = funcStr.match(/\((.*?)\)/)?.[1] || "";
if (params) {
// Handle simple parameters
const paramTypes = params
.split(",")
.map((param) => {
const [name, type] = param.trim().split(":");
return `${name.trim()}${type ? `: ${type.trim()}` : ": any"}`;
})
.join(", ");
type += ` "${key}": (${paramTypes}) => string;\n`;
} else {
type += ` "${key}": () => string;\n`;
}
} else if (typeof value === "object" && value !== null) {
type += ` "${key}": {\n`;
type += generateLanguageType(value, fullKey);
type += ` };\n`;
}
}

return type;
}

function writeLanguageDefinitionToFile() {
const languageType = `export interface LanguageDefinition {\n${generateLanguageType(
en
)}}\n`;

const filePath = path.join(__dirname, "languageDefinition.ts");

fs.writeFileSync(filePath, languageType, "utf8");

console.log(`Language definition has been written to ${filePath}`);
}

// Run the function
writeLanguageDefinitionToFile();
Loading

0 comments on commit e853bb3

Please sign in to comment.