mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-04-03 22:17:24 +02:00
Translations POC
This commit is contained in:
parent
3f9a7702d4
commit
0b69c1882b
13 changed files with 4853 additions and 543 deletions
31
i18next.config.ts
Normal file
31
i18next.config.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { defineConfig } from 'i18next-cli';
|
||||||
|
import { type Plugin, ExtractedKey } from "i18next-cli";
|
||||||
|
import { readFile } from "node:fs/promises";
|
||||||
|
|
||||||
|
const HTMLPlugin: Plugin = {
|
||||||
|
name: "html-plugin",
|
||||||
|
async onEnd(keys: Map<string, ExtractedKey>) {
|
||||||
|
const content = await readFile("src/index.html", "utf-8");
|
||||||
|
const matches = content.matchAll(/data-(?:text|tip)="([^"]+)"/g);
|
||||||
|
for (const match of matches) {
|
||||||
|
const key = match[1];
|
||||||
|
keys.set(key, {key, defaultValue: key});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
locales: [
|
||||||
|
"en",
|
||||||
|
"fr"
|
||||||
|
],
|
||||||
|
extract: {
|
||||||
|
input: "src/**/*.{js,ts}",
|
||||||
|
output: "public/locales/{{language}}/{{namespace}}.json",
|
||||||
|
defaultNS: "lang",
|
||||||
|
keySeparator: false
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
HTMLPlugin
|
||||||
|
]
|
||||||
|
});
|
||||||
1629
package-lock.json
generated
1629
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -21,7 +21,8 @@
|
||||||
"test:browser": "vitest --config=vitest.browser.config.ts",
|
"test:browser": "vitest --config=vitest.browser.config.ts",
|
||||||
"test:e2e": "playwright test",
|
"test:e2e": "playwright test",
|
||||||
"lint": "biome check --write",
|
"lint": "biome check --write",
|
||||||
"format": "biome format --write"
|
"format": "biome format --write",
|
||||||
|
"i18n": "npx i18next-cli extract"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "2.3.13",
|
"@biomejs/biome": "2.3.13",
|
||||||
|
|
@ -32,6 +33,7 @@
|
||||||
"@types/polylabel": "^1.1.3",
|
"@types/polylabel": "^1.1.3",
|
||||||
"@vitest/browser": "^4.0.18",
|
"@vitest/browser": "^4.0.18",
|
||||||
"@vitest/browser-playwright": "^4.0.18",
|
"@vitest/browser-playwright": "^4.0.18",
|
||||||
|
"i18next-cli": "^1.49.6",
|
||||||
"playwright": "^1.57.0",
|
"playwright": "^1.57.0",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"vite": "^7.3.1",
|
"vite": "^7.3.1",
|
||||||
|
|
@ -41,6 +43,8 @@
|
||||||
"alea": "^1.0.1",
|
"alea": "^1.0.1",
|
||||||
"d3": "^7.9.0",
|
"d3": "^7.9.0",
|
||||||
"delaunator": "^5.0.1",
|
"delaunator": "^5.0.1",
|
||||||
|
"i18next": "^25.8.17",
|
||||||
|
"i18next-http-backend": "^3.0.2",
|
||||||
"polylabel": "^2.0.1"
|
"polylabel": "^2.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
||||||
1188
public/locales/en/lang.json
Normal file
1188
public/locales/en/lang.json
Normal file
File diff suppressed because it is too large
Load diff
1188
public/locales/fr/lang.json
Normal file
1188
public/locales/fr/lang.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -220,6 +220,7 @@ oceanLayers
|
||||||
.attr("height", graphHeight);
|
.attr("height", graphHeight);
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
if (window.locale !== "en") await i18n;
|
||||||
if (!location.hostname) {
|
if (!location.hostname) {
|
||||||
const wiki = "https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Run-FMG-locally";
|
const wiki = "https://github.com/Azgaar/Fantasy-Map-Generator/wiki/Run-FMG-locally";
|
||||||
alertMessage.innerHTML = /* html */ `Fantasy Map Generator cannot run serverless. Follow the <a href="${wiki}" target="_blank">instructions</a> on how you can easily run a local web-server`;
|
alertMessage.innerHTML = /* html */ `Fantasy Map Generator cannot run serverless. Follow the <a href="${wiki}" target="_blank">instructions</a> on how you can easily run a local web-server`;
|
||||||
|
|
|
||||||
831
src/index.html
831
src/index.html
File diff suppressed because it is too large
Load diff
|
|
@ -1,3 +1,4 @@
|
||||||
|
import "./locales";
|
||||||
import "./voronoi";
|
import "./voronoi";
|
||||||
import "./heightmap-generator";
|
import "./heightmap-generator";
|
||||||
import "./features";
|
import "./features";
|
||||||
|
|
|
||||||
55
src/modules/locales.ts
Normal file
55
src/modules/locales.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
import i18next from "i18next";
|
||||||
|
import i18nextHTTPBackend from "i18next-http-backend";
|
||||||
|
import { isVowel } from "../utils";
|
||||||
|
|
||||||
|
window.locale = "fr";
|
||||||
|
|
||||||
|
function updateLabels() {
|
||||||
|
for (const label of document.querySelectorAll("[data-text]")) {
|
||||||
|
const translation = i18next.t(label.getAttribute("data-text"));
|
||||||
|
if (translation) label.innerHTML = translation;
|
||||||
|
}
|
||||||
|
for (const tip of document.querySelectorAll("[data-tip]")) {
|
||||||
|
const translation = i18next.t(tip.getAttribute("data-tip"));
|
||||||
|
if (translation) tip.setAttribute("data-tip", translation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.i18n = i18next.use(i18nextHTTPBackend).init(
|
||||||
|
{
|
||||||
|
lng: window.locale,
|
||||||
|
//debug: true,
|
||||||
|
backend: {
|
||||||
|
loadPath: "locales/{{lng}}/lang.json",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
if (document.readyState === "complete") {
|
||||||
|
updateLabels();
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
updateLabels();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
i18next.services.formatter.add("gender", (value, lng, options) => {
|
||||||
|
if (lng !== "fr") return value;
|
||||||
|
else if (options.gender === "feminine") {
|
||||||
|
return value.endsWith("en") ? `${value}ne` : `${value}e`;
|
||||||
|
} else return value;
|
||||||
|
});
|
||||||
|
|
||||||
|
i18next.services.formatter.add("of", (value, lng, options) => {
|
||||||
|
if (lng !== "fr") return value;
|
||||||
|
else if (isVowel(value[0].toLowerCase())) return `d'${value}`;
|
||||||
|
else return `de ${value}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
i18next.services.formatter.add("the", (value, lng, options) => {
|
||||||
|
if (lng !== "fr") return value;
|
||||||
|
else if (isVowel(value[0].toLowerCase())) return `L'${value}`;
|
||||||
|
else if (options.gender === "feminine") return `La ${value}`;
|
||||||
|
else return `Le ${value}`;
|
||||||
|
});
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import i18next from "i18next";
|
||||||
import { capitalize, isVowel, last, P, ra, rand } from "../utils";
|
import { capitalize, isVowel, last, P, ra, rand } from "../utils";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|
@ -263,7 +264,7 @@ class NamesGenerator {
|
||||||
} else if (P(0.4)) return name; // 60% for cc and vc
|
} else if (P(0.4)) return name; // 60% for cc and vc
|
||||||
|
|
||||||
// define suffix
|
// define suffix
|
||||||
let suffix = "ia"; // standard suffix
|
let suffix = i18next.t("ia"); // standard suffix
|
||||||
|
|
||||||
const rnd = Math.random(),
|
const rnd = Math.random(),
|
||||||
l = name.length;
|
l = name.length;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
import { mean, median, sum } from "d3";
|
import { mean, median, sum } from "d3";
|
||||||
|
import i18next from "i18next";
|
||||||
import {
|
import {
|
||||||
byId,
|
byId,
|
||||||
each,
|
each,
|
||||||
gauss,
|
gauss,
|
||||||
|
gender,
|
||||||
getAdjective,
|
getAdjective,
|
||||||
getMixedColor,
|
getMixedColor,
|
||||||
getPolesOfInaccessibility,
|
getPolesOfInaccessibility,
|
||||||
|
|
@ -56,6 +58,19 @@ export interface State {
|
||||||
alert?: number;
|
alert?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gender.fr = {
|
||||||
|
...gender.fr,
|
||||||
|
Confederation: "feminine",
|
||||||
|
Diarchy: "feminine",
|
||||||
|
Horde: "feminine",
|
||||||
|
League: "feminine",
|
||||||
|
Oligarchy: "feminine",
|
||||||
|
Tetrarchy: "feminine",
|
||||||
|
Theocracy: "feminine",
|
||||||
|
"Trade Company": "feminine",
|
||||||
|
Union: "feminine",
|
||||||
|
};
|
||||||
|
|
||||||
class StatesModule {
|
class StatesModule {
|
||||||
private createStates() {
|
private createStates() {
|
||||||
const states: State[] = [{ i: 0, name: "Neutrals" } as State];
|
const states: State[] = [{ i: 0, name: "Neutrals" } as State];
|
||||||
|
|
@ -816,12 +831,25 @@ class StatesModule {
|
||||||
"Marches",
|
"Marches",
|
||||||
];
|
];
|
||||||
if (!state.formName) return state.name;
|
if (!state.formName) return state.name;
|
||||||
if (!state.name && state.formName) return `The ${state.formName}`;
|
const stateGender = gender[window.locale]?.[state.formName];
|
||||||
|
if (!state.name && state.formName)
|
||||||
|
return i18next.t("The {{noun}}", {
|
||||||
|
noun: i18next.t(state.formName),
|
||||||
|
gender: stateGender,
|
||||||
|
});
|
||||||
const adjName =
|
const adjName =
|
||||||
adjForms.includes(state.formName) && !/-| /.test(state.name);
|
adjForms.includes(state.formName) && !/-| /.test(state.name);
|
||||||
return adjName
|
return adjName
|
||||||
? `${getAdjective(state.name)} ${state.formName}`
|
? i18next.t("{{adjective}} {{noun}}", {
|
||||||
: `${state.formName} of ${state.name}`;
|
adjective: getAdjective(state.name),
|
||||||
|
noun: i18next.t(state.formName),
|
||||||
|
gender: stateGender,
|
||||||
|
})
|
||||||
|
: i18next.t("{{noun}} of {{complement}}", {
|
||||||
|
noun: i18next.t(state.formName),
|
||||||
|
complement: state.name,
|
||||||
|
gender: stateGender,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ window.lerp = lerp as typeof window.lerp;
|
||||||
|
|
||||||
import {
|
import {
|
||||||
abbreviate,
|
abbreviate,
|
||||||
|
gender,
|
||||||
getAdjective,
|
getAdjective,
|
||||||
isVowel,
|
isVowel,
|
||||||
list,
|
list,
|
||||||
|
|
@ -298,6 +299,7 @@ export {
|
||||||
findGridCell,
|
findGridCell,
|
||||||
findPath,
|
findPath,
|
||||||
gauss,
|
gauss,
|
||||||
|
gender,
|
||||||
generateDate,
|
generateDate,
|
||||||
generateGrid,
|
generateGrid,
|
||||||
generateSeed,
|
generateSeed,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
import { last } from "./arrayUtils";
|
import { last } from "./arrayUtils";
|
||||||
import { P } from "./probabilityUtils";
|
import { P } from "./probabilityUtils";
|
||||||
|
|
||||||
|
export const gender = {
|
||||||
|
fr: {},
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if character is a vowel
|
* Check if character is a vowel
|
||||||
* @param c - The character to check.
|
* @param c - The character to check.
|
||||||
|
|
@ -30,139 +34,302 @@ export const trimVowels = (string: string, minLength: number = 3) => {
|
||||||
* @returns The adjective form of the noun.
|
* @returns The adjective form of the noun.
|
||||||
*/
|
*/
|
||||||
export const getAdjective = (nounToBeAdjective: string) => {
|
export const getAdjective = (nounToBeAdjective: string) => {
|
||||||
const adjectivizationRules = [
|
const adjectivizationRules = {
|
||||||
{
|
en: [
|
||||||
name: "guo",
|
{
|
||||||
probability: 1,
|
name: "guo",
|
||||||
condition: / Guo$/,
|
probability: 1,
|
||||||
action: (noun: string) => noun.slice(0, -4),
|
condition: / Guo$/,
|
||||||
},
|
action: (noun: string) => noun.slice(0, -4),
|
||||||
{
|
|
||||||
name: "orszag",
|
|
||||||
probability: 1,
|
|
||||||
condition: /orszag$/,
|
|
||||||
action: (noun: string) =>
|
|
||||||
noun.length < 9 ? `${noun}ian` : noun.slice(0, -6),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "stan",
|
|
||||||
probability: 1,
|
|
||||||
condition: /stan$/,
|
|
||||||
action: (noun: string) =>
|
|
||||||
noun.length < 9 ? `${noun}i` : trimVowels(noun.slice(0, -4)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "land",
|
|
||||||
probability: 1,
|
|
||||||
condition: /land$/,
|
|
||||||
action: (noun: string) => {
|
|
||||||
if (noun.length > 9) return noun.slice(0, -4);
|
|
||||||
const root = trimVowels(noun.slice(0, -4), 0);
|
|
||||||
if (root.length < 3) return `${noun}ic`;
|
|
||||||
if (root.length < 4) return `${root}lish`;
|
|
||||||
return `${root}ish`;
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
name: "orszag",
|
||||||
name: "que",
|
probability: 1,
|
||||||
probability: 1,
|
condition: /orszag$/,
|
||||||
condition: /que$/,
|
action: (noun: string) =>
|
||||||
action: (noun: string) => noun.replace(/que$/, "can"),
|
noun.length < 9 ? `${noun}ian` : noun.slice(0, -6),
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "a",
|
|
||||||
probability: 1,
|
|
||||||
condition: /a$/,
|
|
||||||
action: (noun: string) => `${noun}n`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "o",
|
|
||||||
probability: 1,
|
|
||||||
condition: /o$/,
|
|
||||||
action: (noun: string) => noun.replace(/o$/, "an"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "u",
|
|
||||||
probability: 1,
|
|
||||||
condition: /u$/,
|
|
||||||
action: (noun: string) => `${noun}an`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "i",
|
|
||||||
probability: 1,
|
|
||||||
condition: /i$/,
|
|
||||||
action: (noun: string) => `${noun}an`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "e",
|
|
||||||
probability: 1,
|
|
||||||
condition: /e$/,
|
|
||||||
action: (noun: string) => `${noun}an`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "ay",
|
|
||||||
probability: 1,
|
|
||||||
condition: /ay$/,
|
|
||||||
action: (noun: string) => `${noun}an`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "os",
|
|
||||||
probability: 1,
|
|
||||||
condition: /os$/,
|
|
||||||
action: (noun: string) => {
|
|
||||||
const root = trimVowels(noun.slice(0, -2), 0);
|
|
||||||
if (root.length < 4) return noun.slice(0, -1);
|
|
||||||
return `${root}ian`;
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
name: "stan",
|
||||||
name: "es",
|
probability: 1,
|
||||||
probability: 1,
|
condition: /stan$/,
|
||||||
condition: /es$/,
|
action: (noun: string) =>
|
||||||
action: (noun: string) => {
|
noun.length < 9 ? `${noun}i` : trimVowels(noun.slice(0, -4)),
|
||||||
const root = trimVowels(noun.slice(0, -2), 0);
|
|
||||||
if (root.length > 7) return noun.slice(0, -1);
|
|
||||||
return `${root}ian`;
|
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
name: "land",
|
||||||
name: "l",
|
probability: 1,
|
||||||
probability: 0.8,
|
condition: /land$/,
|
||||||
condition: /l$/,
|
action: (noun: string) => {
|
||||||
action: (noun: string) => `${noun}ese`,
|
if (noun.length > 9) return noun.slice(0, -4);
|
||||||
},
|
const root = trimVowels(noun.slice(0, -4), 0);
|
||||||
{
|
if (root.length < 3) return `${noun}ic`;
|
||||||
name: "n",
|
if (root.length < 4) return `${root}lish`;
|
||||||
probability: 0.8,
|
return `${root}ish`;
|
||||||
condition: /n$/,
|
},
|
||||||
action: (noun: string) => `${noun}ese`,
|
},
|
||||||
},
|
{
|
||||||
{
|
name: "que",
|
||||||
name: "ad",
|
probability: 1,
|
||||||
probability: 0.8,
|
condition: /que$/,
|
||||||
condition: /ad$/,
|
action: (noun: string) => noun.replace(/que$/, "can"),
|
||||||
action: (noun: string) => `${noun}ian`,
|
},
|
||||||
},
|
{
|
||||||
{
|
name: "a",
|
||||||
name: "an",
|
probability: 1,
|
||||||
probability: 0.8,
|
condition: /a$/,
|
||||||
condition: /an$/,
|
action: (noun: string) => `${noun}n`,
|
||||||
action: (noun: string) => `${noun}ian`,
|
},
|
||||||
},
|
{
|
||||||
{
|
name: "o",
|
||||||
name: "ish",
|
probability: 1,
|
||||||
probability: 0.25,
|
condition: /o$/,
|
||||||
condition: /^[a-zA-Z]{6}$/,
|
action: (noun: string) => noun.replace(/o$/, "an"),
|
||||||
action: (noun: string) => `${trimVowels(noun.slice(0, -1))}ish`,
|
},
|
||||||
},
|
{
|
||||||
{
|
name: "u",
|
||||||
name: "an",
|
probability: 1,
|
||||||
probability: 0.5,
|
condition: /u$/,
|
||||||
condition: /^[a-zA-Z]{0,7}$/,
|
action: (noun: string) => `${noun}an`,
|
||||||
action: (noun: string) => `${trimVowels(noun)}an`,
|
},
|
||||||
},
|
{
|
||||||
];
|
name: "i",
|
||||||
for (const rule of adjectivizationRules) {
|
probability: 1,
|
||||||
|
condition: /i$/,
|
||||||
|
action: (noun: string) => `${noun}an`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "e",
|
||||||
|
probability: 1,
|
||||||
|
condition: /e$/,
|
||||||
|
action: (noun: string) => `${noun}an`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ay",
|
||||||
|
probability: 1,
|
||||||
|
condition: /ay$/,
|
||||||
|
action: (noun: string) => `${noun}an`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "os",
|
||||||
|
probability: 1,
|
||||||
|
condition: /os$/,
|
||||||
|
action: (noun: string) => {
|
||||||
|
const root = trimVowels(noun.slice(0, -2), 0);
|
||||||
|
if (root.length < 4) return noun.slice(0, -1);
|
||||||
|
return `${root}ian`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "es",
|
||||||
|
probability: 1,
|
||||||
|
condition: /es$/,
|
||||||
|
action: (noun: string) => {
|
||||||
|
const root = trimVowels(noun.slice(0, -2), 0);
|
||||||
|
if (root.length > 7) return noun.slice(0, -1);
|
||||||
|
return `${root}ian`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "l",
|
||||||
|
probability: 0.8,
|
||||||
|
condition: /l$/,
|
||||||
|
action: (noun: string) => `${noun}ese`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "n",
|
||||||
|
probability: 0.8,
|
||||||
|
condition: /n$/,
|
||||||
|
action: (noun: string) => `${noun}ese`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ad",
|
||||||
|
probability: 0.8,
|
||||||
|
condition: /ad$/,
|
||||||
|
action: (noun: string) => `${noun}ian`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "an",
|
||||||
|
probability: 0.8,
|
||||||
|
condition: /an$/,
|
||||||
|
action: (noun: string) => `${noun}ian`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ish",
|
||||||
|
probability: 0.25,
|
||||||
|
condition: /^[a-zA-Z]{6}$/,
|
||||||
|
action: (noun: string) => `${trimVowels(noun.slice(0, -1))}ish`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "an",
|
||||||
|
probability: 0.5,
|
||||||
|
condition: /^[a-zA-Z]{0,7}$/,
|
||||||
|
action: (noun: string) => `${trimVowels(noun)}an`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fr: [
|
||||||
|
{
|
||||||
|
name: "guo",
|
||||||
|
probability: 1,
|
||||||
|
condition: / Guo$/,
|
||||||
|
action: (noun: string) => noun.slice(0, -4),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "orszag",
|
||||||
|
probability: 1,
|
||||||
|
condition: /orszag$/,
|
||||||
|
action: (noun: string) =>
|
||||||
|
noun.length < 9 ? `${noun}ian` : noun.slice(0, -6),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "stan",
|
||||||
|
probability: 1,
|
||||||
|
condition: /stan$/,
|
||||||
|
action: (noun: string) => `${noun}ais`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "land",
|
||||||
|
probability: 1,
|
||||||
|
condition: /land$/,
|
||||||
|
action: (noun: string) => `${noun}ais`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "que",
|
||||||
|
probability: 1,
|
||||||
|
condition: /que$/,
|
||||||
|
action: (noun: string) => noun.replace(/que$/, "cain"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ia",
|
||||||
|
probability: 1,
|
||||||
|
condition: /ia$/,
|
||||||
|
action: (noun: string) => noun.replace(/a$/, "en"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a",
|
||||||
|
probability: 1,
|
||||||
|
condition: /a$/,
|
||||||
|
action: (noun: string) => `${noun}n`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "o",
|
||||||
|
probability: 1,
|
||||||
|
condition: /o$/,
|
||||||
|
action: (noun: string) => `${noun}lais`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "u",
|
||||||
|
probability: 1,
|
||||||
|
condition: /u$/,
|
||||||
|
action: (noun: string) => `${noun}en`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "i",
|
||||||
|
probability: 1,
|
||||||
|
condition: /i$/,
|
||||||
|
action: (noun: string) => `${noun}en`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ie",
|
||||||
|
probability: 1,
|
||||||
|
condition: /e$/,
|
||||||
|
action: (noun: string) => `${noun}n`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "e",
|
||||||
|
probability: 0.5,
|
||||||
|
condition: /e$/,
|
||||||
|
action: (noun: string) => noun.replace(/e$/, "ais"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "e",
|
||||||
|
probability: 0.5,
|
||||||
|
condition: /e$/,
|
||||||
|
action: (noun: string) => noun.replace(/e$/, "ois"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "e",
|
||||||
|
probability: 0.5,
|
||||||
|
condition: /e$/,
|
||||||
|
action: (noun: string) => noun.replace(/e$/, "ien"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "e",
|
||||||
|
probability: 1,
|
||||||
|
condition: /e$/,
|
||||||
|
action: (noun: string) => noun.replace(/e$/, "éen"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ay",
|
||||||
|
probability: 1,
|
||||||
|
condition: /ay$/,
|
||||||
|
action: (noun: string) => `${noun}en`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "os",
|
||||||
|
probability: 1,
|
||||||
|
condition: /os$/,
|
||||||
|
action: (noun: string) => {
|
||||||
|
const root = trimVowels(noun.slice(0, -2), 0);
|
||||||
|
if (root.length < 4) return noun.slice(0, -1);
|
||||||
|
return `${root}ien`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "es",
|
||||||
|
probability: 1,
|
||||||
|
condition: /es$/,
|
||||||
|
action: (noun: string) => {
|
||||||
|
const root = trimVowels(noun.slice(0, -2), 0);
|
||||||
|
if (root.length > 7) return noun.slice(0, -1);
|
||||||
|
return `${root}ien`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "l",
|
||||||
|
probability: 0.8,
|
||||||
|
condition: /l$/,
|
||||||
|
action: (noun: string) => `${noun}ais`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "n",
|
||||||
|
probability: 0.8,
|
||||||
|
condition: /n$/,
|
||||||
|
action: (noun: string) => `${noun}ais`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "n",
|
||||||
|
probability: 0.5,
|
||||||
|
condition: /n$/,
|
||||||
|
action: (noun: string) => `${noun}ois`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ad",
|
||||||
|
probability: 0.8,
|
||||||
|
condition: /ad$/,
|
||||||
|
action: (noun: string) => `${noun}ien`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "an",
|
||||||
|
probability: 0.8,
|
||||||
|
condition: /an$/,
|
||||||
|
action: (noun: string) => `${noun}ien`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ish",
|
||||||
|
probability: 0.25,
|
||||||
|
condition: /^[a-zA-Z]{6}$/,
|
||||||
|
action: (noun: string) => `${trimVowels(noun.slice(0, -1))}ish`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "an",
|
||||||
|
probability: 0.5,
|
||||||
|
condition: /^[a-zA-Z]{0,7}$/,
|
||||||
|
action: (noun: string) => `${trimVowels(noun)}an`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
for (const rule of adjectivizationRules[window.locale]) {
|
||||||
if (P(rule.probability) && rule.condition.test(nounToBeAdjective)) {
|
if (P(rule.probability) && rule.condition.test(nounToBeAdjective)) {
|
||||||
return rule.action(nounToBeAdjective);
|
return rule.action(nounToBeAdjective);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue