ugfx/src/gtrans/gtrans.h

87 lines
2.4 KiB
C
Raw Normal View History

2016-02-07 20:57:03 +00:00
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
2018-10-01 15:32:39 +00:00
* http://ugfx.io/license.html
2016-02-07 20:57:03 +00:00
*/
/**
* @file src/gtrans/gtrans.h
*
* @addtogroup GTRANS
*
2016-02-07 23:03:30 +00:00
* @brief Module that allows changing the language of an application dynamically during run-time.
2016-02-07 20:57:03 +00:00
*
* @{
*/
#ifndef _TRANS_H
#define _TRANS_H
#include "../../gfx.h"
#if GFX_USE_GTRANS || defined(__DOXYGEN__)
2016-02-07 23:03:30 +00:00
/**
* @struct transTable
* @brief A table containing translated strings.
*/
2016-02-07 21:59:35 +00:00
typedef struct transTable {
2016-02-07 23:03:30 +00:00
unsigned numEntries; /**< The number of strings that this table contains */
const char** strings; /**< The translated strings */
2016-02-07 21:59:35 +00:00
} transTable;
2016-02-07 23:03:30 +00:00
/**
* @brief A wrapper macro to make writing and reading translatable applications easier.
*/
#define gt(str) gtransString(str)
/**
* @brief Get the string of the current language specified by the string of the base language.
*
* @details This function will return the string of the current language that corresponds to
* the specified string in the base language.
* @details This function uses strcmp() internally to compare strings.
*
* @param[in] string The string to translate.
*
* @return The corresponding string of the current language or the string passed as a parameter if it doesn't exist.
*/
2016-02-07 21:59:35 +00:00
const char* gtransString(const char* string);
2016-02-07 23:03:30 +00:00
/**
* @brief Get the string at the specified index position of the current language.
*
* @details Getting translation strings is a lot faster using the index as an accessor rather
* than the string in the base language.
*
* @param[in] index The index of the string in the current language translation table.
*
* @return The string at the given index of the current language or 0 if it doesn't exist.
*/
2016-02-07 21:59:35 +00:00
const char* gtransIndex(unsigned index);
2016-02-07 23:03:30 +00:00
/**
* @brief Set the base language.
*
* @details A translatable application needs to have a base language. All translations will
* be relative to this base language.
*
* @param[in] translation The translation table
*/
2016-02-07 21:59:35 +00:00
void gtransSetBaseLanguage(const transTable* const translation);
2016-02-07 23:03:30 +00:00
/**
* @brief Set the current language.
*
* @details All translations will refer to the current language set by calling this function.
*
* @param[in] translation The translation table
*/
2016-02-07 21:59:35 +00:00
void gtransSetLanguage(const transTable* const translation);
2016-02-07 20:57:03 +00:00
#endif /* GFX_USE_GTRANS */
#endif /* _TRANS_H */
/** @} */