The Battle for Wesnoth  1.15.2+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 //this module controls internationalization.
23 
24 class config;
25 
27 {
29  localename(),
30  alternates(),
31  language(),
32  sort_name(),
33  rtl(false),
34  percent(100)
35  {}
36 
37  language_def(const std::string& name, const t_string& lang, const std::string& dir,
38  const std::string &salternates = "", const std::string& sort_name = "", const std::string& percent = "100") :
39  localename(name),
40  alternates(utils::split(salternates)),
41  language(lang),
42  sort_name(sort_name.empty() ? std::string(lang) : sort_name),
43  rtl(dir == "rtl")
44  {
45  try {
46  this->percent = percent.empty() ? 100 : std::stoi(percent);
47  } catch(const std::invalid_argument&) {
48  this->percent = 100;
49  }
50  }
51 
52  std::string localename;
53  std::vector<std::string> alternates;
55  std::string sort_name;
56  bool rtl; // A right to left language? (e.g: Hebrew)
57  /** % of translated text in core po-s */
58  int percent;
59  bool operator== (const language_def&) const;
60  bool operator< (const language_def& a) const
61  { return sort_name < a.sort_name; }
62 };
63 
64 typedef std::vector<language_def> language_list;
65 
67 {
68  const t_string& operator[](const std::string& key) const;
69  const t_string& operator[](const char* key) const;
70 };
71 
72 //table of strings which are displayed to the user. Maps ids -> text.
73 //this table should be consulted whenever something is to be
74 //displayed on screen.
76 
77 bool& time_locale_correct();
78 
79 //function which, given the main configuration object, will return
80 //a list of the translations of the game available.
81 std::vector<language_def> get_languages();
82 
83 //function which, given the main configuration object, and a locale,
84 //will set string_table to be populated with data from that locale.
85 //locale may be either the full name of the language, like 'English',
86 //or the 2-letter version, like 'en'.
87 void set_language(const language_def& locale);
88 
89 //function which returns the name of the language currently used
90 const language_def& get_language();
92 
93 //function which attempts to query and return the locale on the system
94 const language_def& get_locale();
95 
96 /** Initializes the list of textdomains from a configuration object */
97 void init_textdomains(const config& cfg);
98 
99 /** Initializes certain English strings */
100 bool init_strings(const config& cfg);
101 
102 bool load_language_list();
103 
void init_textdomains(const config &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:303
#define a
STL namespace.
std::vector< language_def > get_languages()
Definition: language.cpp:115
bool operator==(const language_def &) const
Definition: language.cpp:58
std::vector< std::string > split(const std::string &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
bool init_strings(const config &cfg)
Initializes certain English strings.
Definition: language.cpp:326
bool operator<(const language_def &a) const
Definition: language.hpp:60
std::string localename
Definition: language.hpp:52
bool load_language_list()
Definition: language.cpp:92
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:37
std::vector< language_def > language_list
Definition: language.hpp:64
void set_language(const language_def &locale)
Definition: language.cpp:221
void set_min_translation_percent(int percent)
Definition: language.cpp:132
const language_def & get_language()
Definition: language.cpp:261
t_string language
Definition: language.hpp:54
int percent
% of translated text in core po-s
Definition: language.hpp:58
symbol_table string_table
Definition: language.cpp:63
const language_def & get_locale()
Definition: language.cpp:263
std::string sort_name
Definition: language.hpp:55
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:53
bool & time_locale_correct()
Definition: language.cpp:65
std::vector< std::string > alternates
Definition: language.hpp:53