diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-29 13:53:38 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-02-29 13:53:38 +0100 |
commit | 846428e0c6d819e5779c671192969f65ce585de3 (patch) | |
tree | 93b1e6bb55fdad243bb51e9409d890140f8a5f57 /core/string/ustring.h | |
parent | 1cc9190c70ac1a1b0e460353f291c1c661fafc9e (diff) | |
parent | d70c45b5c85022fb02224235ff6df24ebf83dcf1 (diff) | |
download | redot-engine-846428e0c6d819e5779c671192969f65ce585de3.tar.gz |
Merge pull request #86222 from YeldhamDev/give_me_those_strings_baby
Add option to add built-in strings in the POT generation
Diffstat (limited to 'core/string/ustring.h')
-rw-r--r-- | core/string/ustring.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/core/string/ustring.h b/core/string/ustring.h index b1348ceb48..468a015302 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -556,6 +556,43 @@ String DTRN(const String &p_text, const String &p_text_plural, int p_n, const St String RTR(const String &p_text, const String &p_context = ""); String RTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = ""); +/** + * "Extractable TRanslate". Used for strings that can appear inside an exported + * project (such as the ones in nodes like `FileDialog`), which are made possible + * to add in the POT generator. A translation context can optionally be specified + * to disambiguate between identical source strings in translations. + * When placeholders are desired, use vformat(ETR("Example: %s"), some_string)`. + * If a string mentions a quantity (and may therefore need a dynamic plural form), + * use `ETRN()` instead of `ETR()`. + * + * NOTE: This function is for string extraction only, and will just return the + * string it was given. The translation itself should be done internally by nodes + * with `atr()` instead. + */ +_FORCE_INLINE_ String ETR(const String &p_text, const String &p_context = "") { + return p_text; +} + +/** + * "Extractable TRanslate for N items". Used for strings that can appear inside an + * exported project (such as the ones in nodes like `FileDialog`), which are made + * possible to add in the POT generator. A translation context can optionally be + * specified to disambiguate between identical source strings in translations. + * Use `ETR()` if the string doesn't need dynamic plural form. When placeholders + * are desired, use `vformat(ETRN("%d item", "%d items", some_integer), some_integer)`. + * The placeholder must be present in both strings to avoid run-time warnings in `vformat()`. + * + * NOTE: This function is for string extraction only, and will just return the + * string it was given. The translation itself should be done internally by nodes + * with `atr()` instead. + */ +_FORCE_INLINE_ String ETRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = "") { + if (p_n == 1) { + return p_text; + } + return p_text_plural; +} + bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end); _FORCE_INLINE_ void sarray_add_str(Vector<String> &arr) { |