Language finished.
This commit is contained in:
@@ -8,12 +8,29 @@
|
||||
#include "localemanager.h"
|
||||
#include "util/memory.h"
|
||||
#include "asset/asset.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
localemanager_t LOCALE;
|
||||
|
||||
errorret_t localeManagerInit() {
|
||||
memoryZero(&LOCALE, sizeof(localemanager_t));
|
||||
|
||||
errorChain(assetLoad("language/us.dlf", &LOCALE));
|
||||
errorChain(localeManagerSetLocale(DUSK_LOCALE_EN_US));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t localeManagerSetLocale(const dusklocale_t locale) {
|
||||
assertTrue(locale < DUSK_LOCALE_COUNT, "Invalid locale.");
|
||||
LOCALE.locale = locale;
|
||||
char_t languageFile[FILENAME_MAX];
|
||||
snprintf(
|
||||
languageFile, FILENAME_MAX, "language/%s.dlf", LOCALE_INFOS[locale].file
|
||||
);
|
||||
assetLanguageDispose(&LOCALE.language);
|
||||
memoryZero(&LOCALE.language, sizeof(assetlanguage_t));
|
||||
errorChain(assetLoad(languageFile, &LOCALE.language));
|
||||
errorOk();
|
||||
}
|
||||
|
||||
void localeManagerDispose() {
|
||||
assetLanguageDispose(&LOCALE.language);
|
||||
}
|
||||
@@ -6,12 +6,30 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "error/error.h"
|
||||
#include "asset/asset.h"
|
||||
|
||||
typedef enum {
|
||||
DUSK_LOCALE_EN_US,
|
||||
|
||||
DUSK_LOCALE_COUNT
|
||||
} dusklocale_t;
|
||||
|
||||
typedef struct {
|
||||
void *nothing;
|
||||
dusklocale_t locale;
|
||||
assetlanguage_t language;
|
||||
} 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;
|
||||
|
||||
/**
|
||||
@@ -19,4 +37,17 @@ extern localemanager_t LOCALE;
|
||||
*
|
||||
* @return An error code if a failure occurs.
|
||||
*/
|
||||
errorret_t localeManagerInit();
|
||||
errorret_t localeManagerInit();
|
||||
|
||||
/**
|
||||
* Set the current locale.
|
||||
*
|
||||
* @param locale The locale to set.
|
||||
* @return An error code if a failure occurs.
|
||||
*/
|
||||
errorret_t localeManagerSetLocale(const dusklocale_t locale);
|
||||
|
||||
/**
|
||||
* Dispose of the locale system.
|
||||
*/
|
||||
void localeManagerDispose();
|
||||
Reference in New Issue
Block a user