Skip to content

Commit

Permalink
locales
Browse files Browse the repository at this point in the history
  • Loading branch information
L3P3 committed Jan 6, 2024
1 parent ae98b68 commit 5699dbf
Show file tree
Hide file tree
Showing 17 changed files with 501 additions and 97 deletions.
2 changes: 1 addition & 1 deletion app-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel=stylesheet href=src/app.css>
</head>
<body>
<script type=module src=https://cdn.jsdelivr.net/gh/L3P3/lui@v1.x/lui.dev.js></script>
<script type=module src=https://cdn.jsdelivr.net/gh/L3P3/lui@dist/lui.dev.js></script>
<script type=module src=src/app.js></script>
<script>
window.ASSETS = '/assets/';
Expand Down
4 changes: 2 additions & 2 deletions app-prod.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<link rel=stylesheet href=dist/app.css>
</head>
<body>
<script defer src=https://cdn.jsdelivr.net/gh/L3P3/lui@v1.x/lui.dev.js></script>
<script defer src=dist/app.js></script>
<script defer src=https://cdn.jsdelivr.net/gh/L3P3/lui@dist/lui.dev.js></script>
<script defer src=dist/app-de.js></script>
<script>
window.ASSETS = '/assets/';
</script>
Expand Down
51 changes: 42 additions & 9 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/env node

import {
readdir,
readFile,
writeFile,
} from 'fs/promises';
Expand All @@ -12,9 +13,19 @@ const TMP_FILE = '/tmp/app.js';

const prod = !!process.env.CI;
const {version} = JSON.parse(
await readFile('./package.json', 'utf-8')
await readFile('./package.json', 'utf8')
);

let languages = ['de'];
if (prod) {
const files = await readdir('./locales');
languages = (
files
.filter(name => name.endsWith('.csv'))
.map(name => name.split('.')[0])
);
}

const exec = cmd => (
new Promise(resolve =>
child_process_exec(
Expand All @@ -24,17 +35,36 @@ const exec = cmd => (
)
);

const env_set = (version, debug, api, api_download) => (
async function lang_generate(lang) {
const csv = await readFile(`./locales/${lang}.csv`, 'utf8');
let output = '';
for (const line of csv.split('\n')) {
if (!line) continue;
const index_colon = line.indexOf(': ');
const key = line.substring(0, index_colon);
const value = line.substring(index_colon + 2);
output += `export const locale_${key} = '${value}';\n`;
}
return output;
}

const env_set = async (version, debug, lang, api, api_download) => Promise.all([
writeFile(
'./src/etc/env.js',
`export const VERSION = '${version}';
export const DEBUG = ${debug};
export const LANG = '${lang}';
export const API = '${api}';
export const API_DOWNLOAD = '${api_download}';
`,
'utf8'
)
);
),
writeFile(
'./src/etc/locale.js',
await lang_generate(lang),
'utf8'
),
]);

async function build_css() {
const css_raw = await readFile('./src/app.css', 'utf8');
Expand All @@ -56,10 +86,11 @@ async function build_css() {
);
}

async function build_js() {
async function build_js(lang) {
await env_set(
prod ? version : 'dev',
false,
lang,
prod ? '/api/minicraft/' : '//l3p3.de/api/minicraft/',
prod ? '/static/minicraft/worlds/' : '//l3p3.de/static/minicraft/worlds/'
);
Expand Down Expand Up @@ -101,7 +132,7 @@ async function build_js() {
'compilation_level SIMPLE',
'externs ./src/externs.js',
'js ' + TMP_FILE,
'js_output_file ./dist/app.js',
`js_output_file ./dist/app-${lang}.js`,
'language_in ECMASCRIPT6_STRICT',
'language_out ECMASCRIPT6_STRICT',
'rewrite_polyfills false',
Expand All @@ -110,7 +141,7 @@ async function build_js() {
]
.join(' --')
))[2]);
console.log('js done.');
console.log(`js ${lang} done.`);

await exec('rm ' + TMP_FILE);
}
Expand All @@ -129,13 +160,15 @@ await exec('rm ./dist/*');
console.log(`build ${version} (${prod ? 'production' : 'dev'})...`);

try {
const lang_first = languages.shift();
await Promise.all([
build_css(),
build_js(),
build_js(lang_first),
]);
for (const lang of languages) await build_js(lang);
}
finally {
await env_set('dev', true, '//l3p3.de/api/minicraft/', '//l3p3.de/static/minicraft/worlds/');
await env_set('dev', true, 'de', '//l3p3.de/api/minicraft/', '//l3p3.de/static/minicraft/worlds/');
}

console.log('done.');
79 changes: 79 additions & 0 deletions locales/de.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
amount: Anzahl
back_to_game: Zurück zum Spiel
chunk_regenerated: Chunk neu generiert.
chunks_loaded: Chunks geladen.
commands: Befehle
download_world_from_server: Welt von Server herunterladen
download: Herunterladen
error_amount_minimum_1: Anzahl muss mindestens 1 sein!
error_conflict_1: Konflikt! Die Welt "
error_conflict_2: " wurde sowohl hier als auch woanders geändert.\nOK: Die vom Server übernehmen (
error_conflict_3: ) | Abbrechen: Die hier hochladen (
error_conflict_4: )
error_connection: Verbindungsfehler.
error_download_world: Fehler beim Herunterladen der Welt:
error_gamemode_range: Spielmodus muss in 0..2 sein!
error_invalid_block_type: Ungültiger Blocktyp!
error_inventory_full: Inventar ist voll!
error_list_is_loading: Liste wird noch geladen!
error_loading_worldlist: Fehler beim Laden der Weltenliste:
error_name_too_long: Der Name ist zu lang!
error_no_permission_logged_in: Keine Berechtigung. Angemeldet?
error_no_world_selected: Keine Welt ausgewählt!
error_not_logged_in: Nicht angemeldet!
error_only_vert_supported: Nur "vert" wird unterstützt!
error_pitch: Pech!
error_selection_required: Auswahl erforderlich!
error_storage: Der Speicherplatz reicht nicht!
error_upload_world: Fehler beim Hochladen der Welt:
error_world_is_loading: Die Welt wird noch geladen!
error_world_is_present_both_sides: Die Welt ist schon auf beiden Seiten vorhanden!
error_world_not_downloaded: Die Welt ist noch nicht heruntergeladen!
game_saved: Spiel gespeichert.
gamemode_set_to: Spielmodus gesetzt auf
inventory_cleared: Inventar geleert
inventory: Inventar
item_labels: Luft,Stein,Grasblock,Erde,Bruchstein,Holzbretter,Grundgestein,Stamm,Laub,Ziegelsteine,Wolle,Sand,Kies,Glas,Bücherregal,Obsidian,Steinziegel,Sandstein,Lapislazuliblock,Eisenblock,Goldblock,Diamantblock,Smaragdblock,Redstoneblock,Quarzblock
items_given: Items gegeben
join_selected_world: Ausgewählte Welt betreten
login: Anmelden
mouse_mode_normal: Normaler Mausmodus.
mouse_mode_selection: Auswahl mit Maustasten.
mouse_sensitivity: Mausempfindlichkeit
name_new_world: Name der neuen Welt:\n(max. 16 Zeichen)
new_world: Neue Welt
only_local: Nur lokale Welt
open: Öffnen
player: Spieler
project_page: Projektseite
refresh: Aktualisieren
reload_list: Liste neu laden
resolution: Auflösung
selection_expanded: Auswahl erweitert.
selection_none: nichts
selection_primary_short: Erster
selection_primary: Erster Auswahlpunkt
selection_secondary_short: Zweiter
selection_secondary: Zweiter Auswahlpunkt
settings: Einstellungen
spawn_updated: Startpunkt aktualisiert.
surfaces_colored: Einfarbig
surfaces_textured: Texturiert
surfaces: Oberflächen
teleported_to_spawn: Zum Startpunkt teleportiert.
teleported_to: Teleportiert zu
transfer: Übertragen
unknown_command: Ungültiger Befehl
unknown_world: Unbekannte Welt
unknown_world_found: Es wurde eine namenlose lokale Welt gefunden. Wie soll sie heißen?
upload_world_to_server: Welt auf den Server hochladen
upload: Hochladen
user_colon: Nutzer:
version_1: Version
version_2: von L3P3
view_angle: Blickwinkel
view_distance: Sichtweite
warn_world_remote_missing_1: Die Welt "
warn_world_remote_missing_2: " wurde auf dem Server nicht gefunden, ist also jetzt eine lokale!
world_leave: Welt verlassen
worlds: Welten
79 changes: 79 additions & 0 deletions locales/en.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
amount: Amount
back_to_game: Back to game
chunk_regenerated: Chunk regenerated.
chunks_loaded: Chunks loaded.
commands: Commands
download_world_from_server: Download world from server
download: Download
error_amount_minimum_1: Amount must be at least 1!
error_conflict_1: Conflict! The world "
error_conflict_2: " was modified here and somewhere else.\nOK: Take variant from server (
error_conflict_3: ) | Cancel: Keep local variant (
error_conflict_4: )
error_connection: Connection error.
error_download_world: Error while downloading world:
error_gamemode_range: Game mode must be in 0..2!
error_invalid_block_type: Invalid block type!
error_inventory_full: Inventory is full!
error_list_is_loading: List is loading!
error_loading_worldlist: Error while loading world list:
error_name_too_long: Name is too long!
error_no_permission_logged_in: Missing permission. Logged in?
error_no_world_selected: No world selected!
error_not_logged_in: Not logged in!
error_only_vert_supported: Only "vert" supported!
error_pitch: Pitch!
error_selection_required: Selection required!
error_storage: Insufficient storage!
error_upload_world: Error while uploading world:
error_world_is_loading: The world is still loading!
error_world_is_present_both_sides: The world is present on both sides!
error_world_not_downloaded: The world is not downloaded yet!
game_saved: Game saved.
gamemode_set_to: Game mode set to
inventory_cleared: Inventory cleared.
inventory: Inventory
item_labels: !!!not used in english!!!
items_given: Gave items
join_selected_world: Enter selected world
login: Login
mouse_mode_normal: Normal mouse mode.
mouse_mode_selection: Select using mouse buttons.
mouse_sensitivity: Mouse sensitivity
name_new_world: New world\'s label:\n(max. 16 characters)
new_world: New world
only_local: Just a local world
open: Enter
player: Player
project_page: Project page
refresh: Refresh
reload_list: Reload list
resolution: Resolution
selection_expanded: Expanded selection.
selection_none: none
selection_primary_short: Primary
selection_primary: Primary point
selection_secondary_short: Secondary
selection_secondary: Secondary point
settings: Settings
spawn_updated: Spawn updated.
surfaces_colored: Plain
surfaces_textured: Textured
surfaces: Surfaces
teleported_to_spawn: Teleported to spawn.
teleported_to: Teleported to
transfer: Transfer
unknown_command: Unknown command
unknown_world: Unknown world
unknown_world_found: There was an unnamed world found. How should it be called?
upload_world_to_server: Upload world to server
upload: Upload
user_colon: User:
version_1: Version
version_2: by L3P3
view_angle: View angle
view_distance: View distance
warn_world_remote_missing_1: The world "
warn_world_remote_missing_2: " was not found on the server, so it is a local world now.
world_leave: Leave world
worlds: Worlds
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minicraft",
"version": "0.9.5",
"version": "0.9.6",
"description": "voxel-based 3d game, written in javascript",
"homepage": "https://l3p3.de/minicraft",
"repository": {
Expand Down
5 changes: 5 additions & 0 deletions src/etc/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
locale_item_labels,
} from './locale.js';

export const APP_VIEW_WORLDS = 0;
export const APP_VIEW_GAME = 1;

Expand Down Expand Up @@ -39,6 +43,7 @@ export const BLOCK_TYPE_QUARTZ_BLOCK = 24;
export const BLOCK_TYPE_MAX = 24;

export const ITEM_HANDLES = 'air,stone,grass,dirt,cobble,planks,bedrock,log,leaves,bricks,wool,sand,gravel,glass,bookshelf,obsidian,stone_bricks,sandstone,lapis_block,iron_block,gold_block,diamond_block,emerald_block,redstone_block,quartz_block'.split(',');
export const ITEM_LABELS = locale_item_labels.split(',');

// B G R
export const BLOCK_COLORS = [
Expand Down
1 change: 1 addition & 0 deletions src/etc/env.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const VERSION = 'dev';
export const DEBUG = true;
export const LANG = 'de';
export const API = '//l3p3.de/api/minicraft/';
export const API_DOWNLOAD = '//l3p3.de/static/minicraft/worlds/';
Loading

0 comments on commit 5699dbf

Please sign in to comment.