Debian Codegraph @

src/engine/translations.h

raw symbols SCIP
1 /***************************************************************************
2 * fheroes2: https://github.com/ihhub/fheroes2 *
3 * Copyright (C) 2019 - 2026 *
4 * *
5 * Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 *
6 * Copyright (C) 2009 by Andrey Afletdinov <[email protected]> *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
23
24 #pragma once
25
26 #include <cstddef>
27 #include <string>
28 #include <string_view>
29 #include <utility>
30
31 namespace Translation
32 {
33 // Sets the language with the given name as the current language if the translation for this language is
34 // already cached and valid, otherwise does nothing. Returns a pair of two flags, the first of which is
35 // set to true if the translation for the given language is already present in the cache (even if this
36 // translation is invalid), and the second is set to true if the current language has been successfully
37 // set.
38 std::pair<bool, bool> setLanguage( const std::string_view langName );
39
40 // Sets the language with the given name as the current language if the translation for this language is
41 // already cached and valid. If this translation is not yet cached, then tries to load it from the given
42 // file. If the load fails, then adds this language to the cache as invalid and does nothing else. Returns
43 // true if the current language has been successfully set, otherwise returns false.
44 bool setLanguage( const std::string & langName, const std::string_view fileName );
45
46 // Resets the current language to the default language (English).
47 void reset();
48
49 const char * gettext( const char * str );
50 const char * gettext( const std::string & str );
51 const char * ngettext( const char * str, const char * plural, const size_t n );
52
53 // Converts the given string to lowercase in a locale aware way
54 std::string StringLower( std::string str );
55
56 // Use it only if you need the original English string but with stripped context.
57 const char * getNonTranslated( const char * str );
58 }
59
60 #define _( str ) Translation::gettext( str )
61 #define _n( str, plural, num ) Translation::ngettext( str, plural, num )
62
63 constexpr const char * gettext_noop( const char * s )
64 {
65 return s;
66 }
67
68 // Replaces the pattern in workString with patternReplacement. The patternReplacement is converted to lowercase in a locale
69 // aware way, except for the first word in a sentence.
70 void StringReplaceWithLowercase( std::string & workString, const char * pattern, const std::string & patternReplacement );