FlightGear next
LanguageInfo.cxx
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Florent Rougon
2// SPDX-License-Identifier: GPL-2.0-or-later
3
8
9#include "LanguageInfo.hxx"
10
11#include <cstdlib>
12#include <map>
13#include <string>
14
15#include <GUI/MessageBox.hxx>
16
17using std::map;
18using std::string;
19
20namespace flightgear {
21
22const map<string, std::size_t> LanguageInfo::nbPluralFormsMap = {
23 {"de", 2},
24 {"default", 1}, // “engineering English” (default translation)
25 {"en", 2}, // English (with singular and plural forms)
26 {"es", 2},
27 {"fr", 2},
28 {"it", 2},
29 {"ka", 2},
30 {"nl", 2},
31 {"pl", 3},
32 {"pt", 2},
33 {"ru", 3},
34 {"tr", 1},
35 {"zh_CN", 1}
36};
37
38// Static member functions
39std::size_t LanguageInfo::pluralFormIndex_EngineeringEnglishStyle(uintType n)
40{
41 return 0;
42}
43
44std::size_t LanguageInfo::pluralFormIndex_EnglishStyle(uintType n)
45{
46 return (n != uintType(1));
47}
48
49std::size_t LanguageInfo::pluralFormIndex_FrenchStyle(uintType n)
50{
51 return (n > uintType(1));
52}
53
54std::size_t LanguageInfo::pluralFormIndex_PolishStyle(uintType n)
55{
56 return (n == uintType(1) ? 0 :
57 n % uintType(10) >= uintType(2) &&
58 n % uintType(10) <= uintType(4) &&
59 (n % uintType(100) < uintType(10) ||
60 n % uintType(100) >= uintType(20)) ? 1 : 2);
61}
62
63std::size_t LanguageInfo::pluralFormIndex_RussianStyle(uintType n)
64{
65 return (n % uintType(10) == uintType(1) &&
66 n % uintType(100) != uintType(11)? 0 :
67 n % uintType(10) >= uintType(2) &&
68 n % uintType(10) <= uintType(4) &&
69 (n % uintType(100) < uintType(10) ||
70 n % uintType(100) >= uintType(20)) ? 1 : 2);
71}
72
73const map<string, LanguageInfo::funcType>
74 LanguageInfo::pluralFormIndexFuncMap = {
75 {"de", pluralFormIndex_EnglishStyle},
76 {"default", pluralFormIndex_EngineeringEnglishStyle},
77 {"en", pluralFormIndex_EnglishStyle},
78 {"es", pluralFormIndex_EnglishStyle},
79 {"fr", pluralFormIndex_FrenchStyle},
80 {"it", pluralFormIndex_EnglishStyle},
81 {"ka", pluralFormIndex_EnglishStyle},
82 {"nl", pluralFormIndex_EnglishStyle},
83 {"pl", pluralFormIndex_PolishStyle},
84 {"pt", pluralFormIndex_EnglishStyle},
85 {"ru", pluralFormIndex_RussianStyle},
86 {"tr", pluralFormIndex_EngineeringEnglishStyle},
87 {"zh_CN", pluralFormIndex_EngineeringEnglishStyle},
88};
89
90// Static member function
91std::size_t LanguageInfo::getNumberOfPluralForms(const string& languageId)
92{
93 const auto it = nbPluralFormsMap.find(languageId);
94
95 if (it == nbPluralFormsMap.end()) {
97 "Unknown language id",
98 "Language id '" + languageId + "' unknown in " __FILE__ ".",
99 "LanguageInfo::getNumberOfPluralForms() was called with language "
100 "id '" + languageId + "', which is not a key of nbPluralFormsMap.");
101 }
102
103 return it->second;
104}
105
106// Static member function
107std::size_t LanguageInfo::getPluralFormIndex(const string& languageId,
108 intType number)
109{
110 const auto it = pluralFormIndexFuncMap.find(languageId);
111
112 if (it == pluralFormIndexFuncMap.end()) {
114 "Unknown language id",
115 "Language id '" + languageId + "' unknown in " __FILE__ ".",
116 "LanguageInfo::getPluralFormIndex() was called with language "
117 "id '" + languageId + "', which is not a key of "
118 "pluralFormIndexFuncMap.");
119 }
120
121 return it->second(std::abs(number));
122}
123
124} // namespace flightgear
Information on plural forms for the supported languages.
static std::size_t getPluralFormIndex(const std::string &languageId, intType number)
Return the index of the plural form to use for a number of “items”
static std::size_t getNumberOfPluralForms(const std::string &languageId)
Return the number of plural forms in the specified language.
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53
void fatalMessageBoxThenExit(const std::string &caption, const std::string &msg, const std::string &moreText, int exitStatus, bool reportToSentry)