Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Language.cpp
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5
6 For more information, see http://www.rigsofrods.org/
7
8 Rigs of Rods is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 3, as
10 published by the Free Software Foundation.
11
12 Rigs of Rods is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19*/
20
24
25#include "Language.h"
26
27#include "Application.h"
28#include "PlatformUtils.h"
29
30using namespace Ogre;
31using namespace RoR;
32
33std::pair<std::string, std::string> extractLang(const std::string& info)
34{
35 String lang_long = "";
36 String lang_short = "";
37 for (const auto& line : StringUtil::split(info, "\n"))
38 {
39 auto token = StringUtil::split(line);
40 if (token[0] == "Language-Team:")
41 lang_long = token[1];
42 else if (token[0] == "Language:")
43 lang_short = token[1];
44 }
45 return {lang_long, lang_short};
46}
47
49{
50 // load language, must happen after initializing Settings class and Ogre Root!
51
52 languages = { {"English", "en"} };
53 auto& moFileReader = moFileLib::moFileReaderSingleton::GetInstance();
54
55 String base_path = PathCombine(App::sys_process_dir->getStr(), "languages");
56 ResourceGroupManager::getSingleton().addResourceLocation(base_path, "FileSystem", "LngRG");
57 FileInfoListPtr fl = ResourceGroupManager::getSingleton().findResourceFileInfo("LngRG", "*", true);
58 if (!fl->empty())
59 {
60 for (const auto& file : *fl)
61 {
62 String locale_path = PathCombine(base_path, file.filename);
63 String mo_path = PathCombine(locale_path, "ror.mo");
64 if (moFileReader.ReadFile(mo_path.c_str()) == moFileLib::moFileReader::EC_SUCCESS)
65 {
66 String info = moFileLib::moFileReaderSingleton::GetInstance().Lookup("");
67 languages.push_back(extractLang(info));
68 }
69 }
70 std::sort(languages.begin() + 1, languages.end());
71 moFileReader.ClearTable();
72 }
73 ResourceGroupManager::getSingleton().destroyResourceGroup("LngRG");
74
75 String locale_path = PathCombine(base_path, App::app_language->getStr().substr(0, 2));
76 String mo_path = PathCombine(locale_path, "ror.mo");
77
78 if (moFileReader.ReadFile(mo_path.c_str()) == moFileLib::moFileReader::EC_SUCCESS)
79 {
80 String info = moFileLib::moFileReaderSingleton::GetInstance().Lookup("");
82 RoR::LogFormat("[RoR|App] Loading language file '%s'", mo_path.c_str());
83 }
84 else
85 {
86 RoR::LogFormat("[RoR|App] Error loading language file: '%s'", mo_path.c_str());
87 return;
88 }
89
90 RoR::Log("[RoR|App] Language successfully loaded");
91}
Central state/object manager and communications hub.
std::pair< std::string, std::string > extractLang(const std::string &info)
Definition Language.cpp:33
Platform-specific utilities. We use narrow UTF-8 encoded strings as paths. Inspired by http://utf8eve...
void setStr(std::string const &str)
Definition CVar.h:83
std::vector< std::pair< std::string, std::string > > languages
Definition Language.h:53
std::string PathCombine(std::string a, std::string b)
CVar * app_language
CVar * sys_process_dir
void Log(const char *msg)
The ultimate, application-wide logging function. Adds a line (any length) in 'RoR....
void LogFormat(const char *format,...)
Improved logging utility. Uses fixed 2Kb buffer.