MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetCurrentLocale

Function GetCurrentLocale

src/strings.cpp:2157–2174  ·  view source on GitHub ↗

* Determine the current charset based on the environment * First check some default values, after this one we passed ourselves * and if none exist return the value for $LANG * @param param environment variable to check conditionally if default ones are not * set. Pass nullptr if you don't want additional checks. * @return return string containing current charset, or nullptr if not-dete

Source from the content-addressed store, hash-verified

2155 * @return return string containing current charset, or nullptr if not-determinable
2156 */
2157std::optional<std::string> GetCurrentLocale(const char *param)
2158{
2159 auto env = GetEnv("LANGUAGE");
2160 if (env.has_value()) return std::string{*env};
2161
2162 env = GetEnv("LC_ALL");
2163 if (env.has_value()) return std::string{*env};
2164
2165 if (param != nullptr) {
2166 env = GetEnv(param);
2167 if (env.has_value()) return std::string{*env};
2168 }
2169
2170 env = GetEnv("LANG");
2171 if (env.has_value()) return std::string{*env};
2172
2173 return std::nullopt;
2174}
2175#else
2176std::optional<std::string> GetCurrentLocale(const char *param);
2177#endif /* !(defined(_WIN32) || defined(__APPLE__)) */

Callers 1

InitializeLanguagePacksFunction · 0.70

Calls 1

GetEnvFunction · 0.85

Tested by

no test coverage detected