Skip to content

Commit

Permalink
Update package.json and localize.macro.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
robincodex committed Mar 30, 2024
1 parent 61c2d42 commit 03021da
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 102 deletions.
45 changes: 43 additions & 2 deletions __tests__/localize_macro_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { parseMacros } from './utils';
import { describe, expect, test } from '@jest/globals';
import { getLocalizationTable } from '../packages/panorama-all-in-jsx/src/localize.macro';
import {
getLocalizationTable,
autoApplyToLocalizationFile
} from '../packages/panorama-all-in-jsx/src/localize.macro';
import { join } from 'path';
import { mkdir, readFile } from 'fs/promises';
import { KeyValues } from 'easy-keyvalues';
import { existsSync } from 'fs';

describe('localize_macro', function () {
test('getLocalizationTable', function () {
test('getLocalizationTable', async function () {
const result = parseMacros(
`
import localize from '../packages/panorama-all-in-jsx/src/localize.macro';
Expand Down Expand Up @@ -43,5 +50,39 @@ describe('localize_macro', function () {
russian: 'Это d'
}
});

const basePath = join(__dirname, 'localization');
await mkdir(basePath, { recursive: true });
const kv = KeyValues.CreateRoot();
kv.CreateChild('lang', []);
kv.Save(join(basePath, 'addon_schinese.txt'), 'utf8');
kv.FindKey('lang')?.CreateChild('addon_game_name', 'My Game');
kv.Save(join(basePath, 'addon_english.txt'), 'utf8');
await autoApplyToLocalizationFile(basePath);
expect(await readFile(join(basePath, 'addon_english.txt'), 'utf8'))
.toBe(`"lang"
{
"addon_game_name" "My Game"
"test_token_a" "this is a"
"test_token_b" "this is b"
"token_f780dc967d9b71be" "this is c"
"token_fa636963348fd7d0" "this is d"
}`);
expect(await readFile(join(basePath, 'addon_schinese.txt'), 'utf8'))
.toBe(`"lang"
{
"test_token_a" "这是a"
"test_token_b" "这是b"
"token_f780dc967d9b71be" "这是c"
"token_fa636963348fd7d0" "这是d"
}`);
expect(await readFile(join(basePath, 'addon_russian.txt'), 'utf8'))
.toBe(`"lang"
{
"test_token_a" "Это a"
"test_token_b" "Это b"
"token_f780dc967d9b71be" "Это c"
"token_fa636963348fd7d0" "Это d"
}`);
});
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
"@types/node": "^20.11.30",
"babel-plugin-macros": "^3.1.0",
"cross-env": "^7.0.3",
"easy-keyvalues": "^1.2.2",
"easy-keyvalues": "^1.2.3",
"html-entities": "^2.5.2",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"rollup": "^4.13.1",
"rollup": "^4.13.2",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-terser": "^7.0.2",
"solid-js": "^1.8.16",
Expand Down
2 changes: 1 addition & 1 deletion packages/panorama-all-in-jsx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solid-panorama-all-in-jsx",
"version": "0.3.8",
"version": "0.3.9",
"description": "",
"engines": {
"node": ">=16.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/panorama-all-in-jsx/src/localize.macro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export async function autoApplyToLocalizationFile(dir: string) {
const filePath = join(dir, `addon_${language}.txt`);
let kv: KeyValues;
if (existsSync(filePath)) {
kv = await KeyValues.Load(filePath);
kv = await KeyValues.Load(filePath, 'utf8');
} else {
kv = KeyValues.CreateRoot();
kv.CreateChild('lang', []);
Expand All @@ -133,6 +133,6 @@ export async function autoApplyToLocalizationFile(dir: string) {
tokenKV.SetValue(table[token]);
}
}
await kv.Save(filePath);
await kv.Save(filePath, 'utf8');
}
}
Loading

0 comments on commit 03021da

Please sign in to comment.