Locale
This commit is contained in:
13
src/locale/localeinfo.h
Normal file
13
src/locale/localeinfo.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "dusk.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char_t *file;
|
||||||
|
} localeinfo_t;
|
||||||
@@ -7,29 +7,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "asset/asset.h"
|
#include "asset/asset.h"
|
||||||
|
#include "localemanager.h"
|
||||||
typedef enum {
|
#include "locale/locale.h"
|
||||||
DUSK_LOCALE_EN_US,
|
|
||||||
|
|
||||||
DUSK_LOCALE_COUNT
|
|
||||||
} dusklocale_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
dusklocale_t locale;
|
dusklocale_t locale;
|
||||||
assetlanguage_t language;
|
assetlanguage_t language;
|
||||||
} localemanager_t;
|
} localemanager_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char_t *file;
|
|
||||||
} localeinfo_t;
|
|
||||||
|
|
||||||
static const localeinfo_t LOCALE_INFOS[DUSK_LOCALE_COUNT] = {
|
|
||||||
[DUSK_LOCALE_EN_US] = {
|
|
||||||
.file = "en_US"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
extern localemanager_t LOCALE;
|
extern localemanager_t LOCALE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
14
src/script/module/modulelocale.h
Normal file
14
src/script/module/modulelocale.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "script/scriptcontext.h"
|
||||||
|
#include "locale/localemanager.h"
|
||||||
|
|
||||||
|
void moduleLocale(scriptcontext_t *context) {
|
||||||
|
assertNotNull(context, "Script context cannot be NULL");
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "script/module/moduleplatform.h"
|
#include "script/module/moduleplatform.h"
|
||||||
#include "script/module/modulescene.h"
|
#include "script/module/modulescene.h"
|
||||||
#include "script/module/moduleitem.h"
|
#include "script/module/moduleitem.h"
|
||||||
|
#include "script/module/modulelocale.h"
|
||||||
|
|
||||||
const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
||||||
{ .name = "system", .callback = moduleSystem },
|
{ .name = "system", .callback = moduleSystem },
|
||||||
@@ -18,6 +19,7 @@ const scriptmodule_t SCRIPT_MODULE_LIST[] = {
|
|||||||
{ .name = "platform", .callback = modulePlatform },
|
{ .name = "platform", .callback = modulePlatform },
|
||||||
{ .name = "scene", .callback = moduleScene },
|
{ .name = "scene", .callback = moduleScene },
|
||||||
{ .name = "item", .callback = moduleItem },
|
{ .name = "item", .callback = moduleItem },
|
||||||
|
{ .name = "locale", .callback = moduleLocale },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SCRIPT_MODULE_COUNT ( \
|
#define SCRIPT_MODULE_COUNT ( \
|
||||||
|
|||||||
@@ -142,13 +142,39 @@ def processLanguageList():
|
|||||||
with open(outputFile, "wb") as f:
|
with open(outputFile, "wb") as f:
|
||||||
f.write(langBuffer)
|
f.write(langBuffer)
|
||||||
|
|
||||||
|
|
||||||
# Write out the language keys header file
|
# Write out the language keys header file
|
||||||
outputFile = os.path.join(args.headers_dir, "locale", "language", "keys.h")
|
outputFile = os.path.join(args.headers_dir, "locale", "language", "keys.h")
|
||||||
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||||
with open(outputFile, "w") as f:
|
with open(outputFile, "w") as f:
|
||||||
f.write(headerKeys)
|
f.write(headerKeys)
|
||||||
|
|
||||||
|
# Generate language list.
|
||||||
|
headerLocale = "#pragma once\n#include \"locale/localeinfo.h\"\n\n"
|
||||||
|
headerLocale += "typedef enum {\n"
|
||||||
|
count = 0
|
||||||
|
headerLocale += f" DUSK_LOCALE_NULL = {count},\n"
|
||||||
|
count += 1
|
||||||
|
for lang in LANGUAGE_DATA:
|
||||||
|
langKey = lang.replace('-', '_').replace(' ', '_').upper()
|
||||||
|
headerLocale += f" DUSK_LOCALE_{langKey} = {count},\n"
|
||||||
|
count += 1
|
||||||
|
headerLocale += f" DUSK_LOCALE_COUNT = {count}\n"
|
||||||
|
headerLocale += "} dusklocale_t;\n\n"
|
||||||
|
|
||||||
|
headerLocale += f"static const localeinfo_t LOCALE_INFOS[DUSK_LOCALE_COUNT] = {{\n"
|
||||||
|
for lang in LANGUAGE_DATA:
|
||||||
|
langKey = lang.replace('-', '_').replace(' ', '_').upper()
|
||||||
|
headerLocale += f" [DUSK_LOCALE_{langKey}] = {{\n"
|
||||||
|
headerLocale += f" .file = \"{lang}\"\n"
|
||||||
|
headerLocale += f" }},\n"
|
||||||
|
headerLocale += "};\n"
|
||||||
|
|
||||||
|
# Write out the locale enum header file
|
||||||
|
outputFile = os.path.join(args.headers_dir, "locale", "locale.h")
|
||||||
|
os.makedirs(os.path.dirname(outputFile), exist_ok=True)
|
||||||
|
with open(outputFile, "w") as f:
|
||||||
|
f.write(headerLocale)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'files': files
|
'files': files
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user