Aurore
A Switch-like interface for your app, on every screen
Loading...
Searching...
No Matches
i18n.hpp
Go to the documentation of this file.
1/*
2 Copyright 2020-2021 natinusala
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
19#include <fmt/format.h>
20
21#include <string>
23
24namespace aurore
25{
26
27const std::string LOCALE_JA = "ja";
28const std::string LOCALE_EN_US = "en-US";
29const std::string LOCALE_EN_GB = "en-GB";
30const std::string LOCALE_FR = "fr";
31const std::string LOCALE_FR_CA = "fr-CA";
32const std::string LOCALE_DE = "de";
33const std::string LOCALE_IT = "it";
34const std::string LOCALE_ES = "es";
35const std::string LOCALE_ZH_CN = "zh-CN";
36const std::string LOCALE_ZH_HANS = "zh-Hans";
37const std::string LOCALE_ZH_HANT = "zh-Hant";
38const std::string LOCALE_ZH_TW = "zh-TW";
39const std::string LOCALE_Ko = "ko";
40const std::string LOCALE_NL = "nl";
41const std::string LOCALE_PT = "pt";
42const std::string LOCALE_PT_BR = "pt-BR";
43const std::string LOCALE_RU = "ru";
44const std::string LOCALE_ES_419 = "es-419";
45
47// Rename ja-RYU to RYU, as there may be a bug in PkgTool that not allow dirs with same prefix exist.
48#ifdef PS4
49const std::string LOCALE_RYU = "RYU";
50#else
51const std::string LOCALE_RYU = "ja-RYU";
52#endif
53const std::string LOCALE_AUTO = "auto";
54
55const std::string LOCALE_DEFAULT = LOCALE_EN_US;
56
62std::string localeFromSystem(std::string system);
63
64namespace internal
65{
66 std::string getRawStr(std::string stringName);
67} // namespace internal
68
73template <typename... Args>
74std::string getStr(std::string stringName, Args&&... args)
75{
76 std::string rawStr = internal::getRawStr(stringName);
77
78 try
79 {
80 return fmt::format(fmt::runtime(rawStr), args...);
81 }
82 catch (const std::exception& e)
83 {
84 Logger::error("Invalid format \"{}\" from string \"{}\": {}", rawStr, stringName, e.what());
85 return stringName;
86 }
87}
88
94
100void loadTranslations(const std::string& locale);
101
102inline namespace literals
103{
109 std::string operator""_i18n(const char* str, size_t len);
110} // namespace literals
111} // namespace aurore
static void error(fmt::format_string< Args... > format, Args &&... args)
Definition logger.hpp:152
std::string getRawStr(std::string stringName)
Definition actions.hpp:25
const std::string LOCALE_PT
Definition i18n.hpp:41
const std::string LOCALE_ES_419
Definition i18n.hpp:44
const std::string LOCALE_JA
Definition i18n.hpp:27
const std::string LOCALE_ZH_HANS
Definition i18n.hpp:36
const std::string LOCALE_ZH_CN
Definition i18n.hpp:35
const std::string LOCALE_FR_CA
Definition i18n.hpp:31
const std::string LOCALE_RYU
custom locale
Definition i18n.hpp:51
const std::string LOCALE_EN_US
Definition i18n.hpp:28
const std::string LOCALE_EN_GB
Definition i18n.hpp:29
const std::string LOCALE_FR
Definition i18n.hpp:30
const std::string LOCALE_ZH_TW
Definition i18n.hpp:38
const std::string LOCALE_PT_BR
Definition i18n.hpp:42
const std::string LOCALE_Ko
Definition i18n.hpp:39
void loadTranslations()
std::string getStr(std::string stringName, Args &&... args)
Definition i18n.hpp:74
const std::string LOCALE_NL
Definition i18n.hpp:40
const std::string LOCALE_DE
Definition i18n.hpp:32
const std::string LOCALE_ES
Definition i18n.hpp:34
const std::string LOCALE_ZH_HANT
Definition i18n.hpp:37
std::string localeFromSystem(std::string system)
const std::string LOCALE_AUTO
Definition i18n.hpp:53
const std::string LOCALE_RU
Definition i18n.hpp:43
const std::string LOCALE_IT
Definition i18n.hpp:33
const std::string LOCALE_DEFAULT
Definition i18n.hpp:55