1 #ifndef LV_I18N_H
2 #define LV_I18N_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include "../../../lvgl.h"
9 #if LV_USE_DEMO_EBIKE
10 
11 #include LV_STDINT_INCLUDE
12 
13 typedef enum {
14     LV_I18N_PLURAL_TYPE_ZERO,
15     LV_I18N_PLURAL_TYPE_ONE,
16     LV_I18N_PLURAL_TYPE_TWO,
17     LV_I18N_PLURAL_TYPE_FEW,
18     LV_I18N_PLURAL_TYPE_MANY,
19     LV_I18N_PLURAL_TYPE_OTHER,
20     _LV_I18N_PLURAL_TYPE_NUM,
21 } lv_i18n_plural_type_t;
22 
23 typedef struct {
24     const char * msg_id;
25     const char * translation;
26 } lv_i18n_phrase_t;
27 
28 typedef struct {
29     const char * locale_name;
30     lv_i18n_phrase_t * singulars;
31     lv_i18n_phrase_t * plurals[_LV_I18N_PLURAL_TYPE_NUM];
32     uint8_t (*locale_plural_fn)(int32_t num);
33 } lv_i18n_lang_t;
34 
35 // Null-terminated list of languages. First one used as default.
36 typedef const lv_i18n_lang_t * lv_i18n_language_pack_t;
37 
38 
39 extern const lv_i18n_language_pack_t lv_i18n_language_pack[];
40 
41 
42 /**
43  * Set the languages for internationalization
44  * @param langs pointer to the array of languages. (Last element has to be `NULL`)
45  */
46 int lv_i18n_init(const lv_i18n_language_pack_t * langs);
47 
48 /**
49  * Change the localization (language)
50  * @param l_name name of the translation locale to use. E.g. "en_GB"
51  */
52 int lv_i18n_set_locale(const char * l_name);
53 
54 /**
55  * Get the translation from a message ID
56  * @param msg_id message ID
57  * @return the translation of `msg_id` on the set local
58  */
59 const char * lv_i18n_get_text(const char * msg_id);
60 
61 /**
62  * Get the translation from a message ID and apply the language's plural rule to get correct form
63  * @param msg_id message ID
64  * @param num an integer to select the correct plural form
65  * @return the translation of `msg_id` on the set local
66  */
67 const char * lv_i18n_get_text_plural(const char * msg_id, int32_t num);
68 
69 /**
70  * Get the name of the currently used localization.
71  * @return name of the currently used localization. E.g. "en_GB"
72  */
73 const char * lv_i18n_get_current_locale(void);
74 
75 
76 void __lv_i18n_reset(void);
77 
78 
79 #define _(text) lv_i18n_get_text(text)
80 #define _p(text, num) lv_i18n_get_text_plural(text, num)
81 
82 #endif /*LV_USE_DEMO_EBIKE*/
83 
84 #ifdef __cplusplus
85 } /* extern "C" */
86 #endif
87 
88 #endif /*LV_LANG_H*/
89