The Battle for Wesnoth  1.15.5+dev
language.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "tstring.hpp"
19 
20 #include <iterator>
21 
22 class game_config_view;
23 
24 //this module controls internationalization.
25 
26 class config;
27 
29 {
31  localename(),
32  alternates(),
33  language(),
34  sort_name(),
35  rtl(false),
36  percent(100)
37  {}
38 
39  language_def(const std::string& name, const t_string& lang, const std::string& dir,
40  const std::string &salternates = "", const std::string& sort_name = "", const std::string& percent = "100") :
41  localename(name),
42  alternates(utils::split(salternates)),
43  language(lang),
44  sort_name(sort_name.empty() ? std::string(lang) : sort_name),
45  rtl(dir == "rtl")
46  {
47  try {
48  this->percent = percent.empty() ? 100 : std::stoi(percent);
49  } catch(const std::invalid_argument&) {
50  this->percent = 100;
51  }
52  }
53 
55  std::vector<std::string> alternates;
58  bool rtl; // A right to left language? (e.g: Hebrew)
59  /** % of translated text in core po-s */
60  int percent;
61  bool operator== (const language_def&) const;
62  bool operator< (const language_def& a) const
63  { return sort_name < a.sort_name; }
64 };
65 
66 typedef std::vector<language_def> language_list;
67 
69 {
70  const t_string& operator[](const std::string& key) const;
71  const t_string& operator[](const char* key) const;
72 };
73 
74 //table of strings which are displayed to the user. Maps ids -> text.
75 //this table should be consulted whenever something is to be
76 //displayed on screen.
78 
79 bool& time_locale_correct();
80 
81 //function which, given the main configuration object, will return
82 //a list of the translations of the game available.
83 std::vector<language_def> get_languages();
84 
85 //function which, given the main configuration object, and a locale,
86 //will set string_table to be populated with data from that locale.
87 //locale may be either the full name of the language, like 'English',
88 //or the 2-letter version, like 'en'.
89 void set_language(const language_def& locale);
90 
91 //function which returns the name of the language currently used
92 const language_def& get_language();
94 
95 //function which attempts to query and return the locale on the system
96 const language_def& get_locale();
97 
98 /** Initializes the list of textdomains from a configuration object */
99 void init_textdomains(const game_config_view& cfg);
100 
101 /** Initializes certain English strings */
102 bool init_strings(const game_config_view& cfg);
103 
104 bool load_language_list();
105 
#define a
bool init_strings(const game_config_view &cfg)
Initializes certain English strings.
Definition: language.cpp:379
STL namespace.
std::vector< language_def > get_languages()
Definition: language.cpp:116
bool operator==(const language_def &) const
Definition: language.cpp:59
bool operator<(const language_def &a) const
Definition: language.hpp:62
std::string localename
Definition: language.hpp:54
bool load_language_list()
Definition: language.cpp:93
language_def(const std::string &name, const t_string &lang, const std::string &dir, const std::string &salternates="", const std::string &sort_name="", const std::string &percent="100")
Definition: language.hpp:39
std::vector< language_def > language_list
Definition: language.hpp:66
void set_language(const language_def &locale)
Definition: language.cpp:276
void set_min_translation_percent(int percent)
Definition: language.cpp:133
const language_def & get_language()
Definition: language.cpp:316
t_string language
Definition: language.hpp:56
int percent
% of translated text in core po-s
Definition: language.hpp:60
symbol_table string_table
Definition: language.cpp:64
std::vector< std::string > split(const config_attribute_value &val)
const language_def & get_locale()
Definition: language.cpp:318
std::string sort_name
Definition: language.hpp:57
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:356
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
bool current_language_rtl()
Definition: language.cpp:54
bool & time_locale_correct()
Definition: language.cpp:66
std::vector< std::string > alternates
Definition: language.hpp:55