83 lines
2.0 KiB
C
83 lines
2.0 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "error/error.h"
|
|
#include "localemanager.h"
|
|
#include "locale/localeinfo.h"
|
|
#include "asset/asset.h"
|
|
|
|
typedef struct {
|
|
const localeinfo_t *locale;
|
|
assetentry_t *entry;
|
|
} localemanager_t;
|
|
|
|
extern localemanager_t LOCALE;
|
|
|
|
/**
|
|
* Initialize the locale system.
|
|
*
|
|
* @return An error code if a failure occurs.
|
|
*/
|
|
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 localeinfo_t *locale);
|
|
|
|
/**
|
|
* Get a localized string for the given message ID.
|
|
*
|
|
* @param id The message ID to retrieve.
|
|
* @param buffer Buffer to write the retrieved string to.
|
|
* @param bufferSize Size of the buffer.
|
|
* @param plural Plural index to retrieve.
|
|
* @param ... Additional arguments for formatting the string.
|
|
* @return An error code if a failure occurs.
|
|
*/
|
|
#define localeManagerGetText(id, buffer, bufferSize, plural, ...) \
|
|
assetLocaleGetStringWithVA( \
|
|
&LOCALE.entry->data.locale, \
|
|
id, \
|
|
plural, \
|
|
buffer, \
|
|
bufferSize, \
|
|
__VA_ARGS__ \
|
|
)
|
|
|
|
/**
|
|
* Get a localized string for the given message ID with a list of arguments.
|
|
*
|
|
* @param id The message ID to retrieve.
|
|
* @param buffer Buffer to write the retrieved string to.
|
|
* @param bufferSize Size of the buffer.
|
|
* @param plural Plural index to retrieve.
|
|
* @param args List of arguments for formatting the string.
|
|
* @param argCount Number of arguments in the list.
|
|
* @return An error code if a failure occurs.
|
|
*/
|
|
#define localeManagerGetTextArgs( \
|
|
id, buffer, bufferSize, plural, args, argCount \
|
|
) \
|
|
assetLocaleGetStringWithArgs( \
|
|
&LOCALE.entry->data.locale, \
|
|
id, \
|
|
plural, \
|
|
buffer, \
|
|
bufferSize, \
|
|
args, \
|
|
argCount \
|
|
)
|
|
|
|
/**
|
|
* Dispose of the locale system.
|
|
*/
|
|
void localeManagerDispose(); |