RigsofRods
Soft-body Physics Simulation
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 
30 using namespace Ogre;
31 using namespace RoR;
32 
33 std::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 
48 void LanguageEngine::setup()
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("");
81  App::app_language->setStr(extractLang(info).second);
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 }
file
This is a raw Ogre binding for Imgui No project cmake file
Definition: README-OgreImGui.txt:3
extractLang
std::pair< std::string, std::string > extractLang(const std::string &info)
Definition: Language.cpp:33
RoR::App::app_language
CVar * app_language
Definition: Application.cpp:80
RoR::LogFormat
void LogFormat(const char *format,...)
Improved logging utility. Uses fixed 2Kb buffer.
Definition: Application.cpp:424
Language.h
RoR::PathCombine
std::string PathCombine(std::string a, std::string b)
Definition: PlatformUtils.h:48
PlatformUtils.h
Platform-specific utilities. We use narrow UTF-8 encoded strings as paths. Inspired by http://utf8eve...
Application.h
Central state/object manager and communications hub.
Ogre
Definition: ExtinguishableFireAffector.cpp:35
RoR::App::sys_process_dir
CVar * sys_process_dir
Definition: Application.cpp:162
RoR
Definition: AppContext.h:36
RoR::Log
void Log(const char *msg)
The ultimate, application-wide logging function. Adds a line (any length) in 'RoR....
Definition: Application.cpp:419
RoR::CVar::setStr
void setStr(std::string const &str)
Definition: CVar.h:83