packages/editor (React 18, Vite) draws a document as Java FILIUS does: Java's default hardware icons, the device button of JSidebarButton, cables as JCablePanel's quadratic curve between the buttons' middles, wireless cables dashed, documentation items below. The surface moves with mouse and finger (the pointer captured only once it moved) and zooms with Ctrl and the wheel, a trackpad pinch, two fingers and the zoom bar; the first view shows all. German and English catalogs with Java's device names, the dashboard's colour tokens, the bridge with its origin check. packages/doc gets the drawing's light view of a document. Java's Switch.cloud (the Internet in the examples) was lost on reading; it is now read, kept in the model and written, with FlsOracle and the corpus, written and exported checks renewed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.8 KiB
TypeScript
59 lines
2.8 KiB
TypeScript
// The catalogs: the same keys in both languages, placeholders filled, and —
|
|
// where Java FILIUS names a thing — Java's word in its bundle (M11).
|
|
|
|
import { existsSync, readFileSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { CATALOGS, translate } from '../src/i18n/i18n.js';
|
|
|
|
const bundles = join(dirname(fileURLToPath(import.meta.url)), '../../../tools/java-oracle/.upstream/src/main/resources/filius/messages');
|
|
|
|
/** A Java .properties file: ISO-8859-1, \uXXXX escapes, `key = value`. */
|
|
function properties(file: string): Map<string, string> {
|
|
const text = new TextDecoder('latin1').decode(readFileSync(join(bundles, file)));
|
|
const entries = new Map<string, string>();
|
|
for (const line of text.split(/\r?\n/)) {
|
|
const match = /^([\w.]+)\s*=\s*(.*)$/.exec(line);
|
|
if (match !== null) entries.set(match[1]!, match[2]!.replace(/\\u([0-9a-fA-F]{4})/g, (_, hex: string) => String.fromCharCode(Number.parseInt(hex, 16))).trim());
|
|
}
|
|
return entries;
|
|
}
|
|
|
|
/** The editor's keys whose words are Java's, and the key of each in Java's bundle. */
|
|
const FROM_JAVA: Readonly<Record<string, string>> = {
|
|
'device.pc': 'hw_rechner_msg1',
|
|
'device.notebook': 'hw_notebook_msg1',
|
|
'device.networkSwitch': 'hw_switch_msg1',
|
|
'device.router': 'hw_vermittlungsrechner_msg1',
|
|
'device.gateway': 'hw_gateway_msg1',
|
|
'device.cable': 'hw_kabel_msg1',
|
|
};
|
|
|
|
describe('the catalogs', () => {
|
|
it('have the same keys in German and English, each with a text', () => {
|
|
expect(Object.keys(CATALOGS.en).sort()).toEqual(Object.keys(CATALOGS.de).sort());
|
|
for (const catalog of Object.values(CATALOGS)) for (const text of Object.values(catalog)) expect(text.trim()).not.toBe('');
|
|
});
|
|
|
|
it('fill placeholders, and show a key they lack', () => {
|
|
expect(translate('de', 'zoom.level', { percent: 75 })).toBe('75 %');
|
|
expect(translate('en', 'zoom.level')).toBe('{percent} %');
|
|
expect(translate('de', 'no.such.key')).toBe('no.such.key');
|
|
});
|
|
|
|
it('name every kind of device', () => {
|
|
for (const kind of ['pc', 'notebook', 'networkSwitch', 'router', 'gateway', 'remoteLink', 'unsupported']) expect(CATALOGS.de[`device.${kind}`]).toBeDefined();
|
|
// Java's Modem.TYPE, the same in every language.
|
|
expect([CATALOGS.de['device.remoteLink'], CATALOGS.en['device.remoteLink']]).toEqual(['Modem', 'Modem']);
|
|
});
|
|
|
|
it.skipIf(!existsSync(bundles))("use Java's words where Java has them (M11)", () => {
|
|
const [de, en] = [properties('MessagesBundle_de_DE.properties'), properties('MessagesBundle_en_GB.properties')];
|
|
for (const [key, javaKey] of Object.entries(FROM_JAVA)) {
|
|
expect(CATALOGS.de[key], key).toBe(de.get(javaKey));
|
|
expect(CATALOGS.en[key], key).toBe(en.get(javaKey));
|
|
}
|
|
});
|
|
});
|