Added proper plural support

This commit is contained in:
2026-04-04 15:21:27 -05:00
parent 64735bdf43
commit 98d70b96d1
7 changed files with 663 additions and 303 deletions
@@ -7,26 +7,66 @@
#pragma once
#include "asset/asset.h"
#include "locale/localemanager.h"
#define ASSET_LOCALE_FILE_PLURAL_FORM_COUNT 6
typedef enum {
ASSET_LOCALE_PLURAL_OP_EQUAL,
ASSET_LOCALE_PLURAL_OP_NOT_EQUAL,
ASSET_LOCALE_PLURAL_OP_LESS,
ASSET_LOCALE_PLURAL_OP_LESS_EQUAL,
ASSET_LOCALE_PLURAL_OP_GREATER,
ASSET_LOCALE_PLURAL_OP_GREATER_EQUAL
} assetlocalepluraloperation_t;
typedef enum {
ASSET_LOCALE_ARG_STRING,
ASSET_LOCALE_ARG_INT,
ASSET_LOCALE_ARG_FLOAT
} assetlocaleargtype_t;
typedef struct {
assetlocaleargtype_t type;
union {
const char_t *stringValue;
int32_t intValue;
float_t floatValue;
};
} assetlocalearg_t;
typedef struct {
assetfile_t file;
assetlocalepluraloperation_t pluralOps[ASSET_LOCALE_FILE_PLURAL_FORM_COUNT];
int32_t pluralValues[ASSET_LOCALE_FILE_PLURAL_FORM_COUNT];
int32_t pluralIndices[ASSET_LOCALE_FILE_PLURAL_FORM_COUNT];
uint8_t pluralStateCount;
uint8_t pluralDefaultIndex;
} assetlocalefile_t;
/**
* Handler for locale assets.
* Initialize a locale asset file.
*
* @param file Asset file to load the locale from.
* @return Any error that occurs during loading.
* @param localeFile The locale file to initialize.
* @param path The path to the locale file.
* @return An error code if a failure occurs.
*/
errorret_t assetLocaleLoader(assetfile_t *file);
errorret_t assetLocaleFileInit(
assetlocalefile_t *localeFile,
const char_t *path
);
/**
* Loads a locale from the specified path.
* Dispose of a locale asset file.
*
* @param path Path to the locale asset.
* @param nothing Nothing yet.
* @return Any error that occurs during loading.
* @param localeFile The locale file to dispose of.
* @return An error code if a failure occurs.
*/
errorret_t assetLocaleLoad(
const char_t *path,
void *nothing
errorret_t assetLocaleFileDispose(assetlocalefile_t *localeFile);
errorret_t assetLocaleParseHeader(
assetlocalefile_t *localeFile,
char_t *headerBuffer,
const size_t headerBufferSize
);
/**
@@ -65,15 +105,57 @@ errorret_t assetLocaleLineUnbuffer(
*
* @param file Asset file to test loading from.
* @param messageId The message ID to retrieve.
* @param pluralIndex The plural index to retrieve.
* @param pluralCount Count for formulating the plural variant.
* @param stringBuffer Buffer to write the retrieved string to.
* @param stringBufferSize Size of the string buffer.
* @return Any error that occurs during testing.
*/
errorret_t assetLocaleGetString(
assetfile_t *file,
assetlocalefile_t *file,
const char_t *messageId,
const int32_t pluralIndex,
const int32_t pluralCount,
char_t *stringBuffer,
const size_t stringBufferSize
);
/**
* Test function for locale asset loading with a variable argument list.
*
* @param file Asset file to test loading from.
* @param messageId The message ID to retrieve.
* @param pluralCount Count for formulating the plural variant.
* @param buffer Buffer to write the retrieved string to.
* @param bufferSize Size of the buffer.
* @param ... Additional arguments for formatting the string.
* @return Any error that occurs during testing.
*/
errorret_t assetLocaleGetStringWithVA(
assetlocalefile_t *file,
const char_t *messageId,
const int32_t pluralCount,
char_t *buffer,
const size_t bufferSize,
...
);
/**
* Test function for locale asset loading with a list of arguments.
*
* @param file Asset file to test loading from.
* @param messageId The message ID to retrieve.
* @param pluralCount Count for formulating the plural variant.
* @param buffer Buffer to write the retrieved string to.
* @param bufferSize Size of the buffer.
* @param args List of arguments for formatting the string.
* @param argCount Number of arguments in the list.
* @return Any error that occurs during testing.
*/
errorret_t assetLocaleGetStringWithArgs(
assetlocalefile_t *file,
const char_t *messageId,
const int32_t pluralCount,
char_t *buffer,
const size_t bufferSize,
const assetlocalearg_t *args,
const size_t argCount
);