The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
language.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef LANGUAGE_HPP_INCLUDED
15 #define LANGUAGE_HPP_INCLUDED
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  {}
35 
36  language_def(const std::string& name, const t_string& lang, const std::string& dir,
37  const std::string &salternates = "", const std::string& sort_name = "") :
38  localename(name),
39  alternates(utils::split(salternates)),
40  language(lang),
41  sort_name(sort_name.empty() ? std::string(lang) : sort_name),
42  rtl(dir == "rtl")
43  {
44  }
45 
47  std::vector<std::string> alternates;
50  bool rtl; // A right to left language? (e.g: Hebrew)
51  bool operator== (const language_def&) const;
52  bool operator< (const language_def& a) const
53  { return sort_name < a.sort_name; }
54 };
55 
56 typedef std::vector<language_def> language_list;
57 
59 {
60  const t_string& operator[](const std::string& key) const;
61  const t_string& operator[](const char* key) const;
62 };
63 
64 //table of strings which are displayed to the user. Maps ids -> text.
65 //this table should be consulted whenever something is to be
66 //displayed on screen.
68 
69 bool& time_locale_correct();
70 
71 //function which, given the main configuration object, will return
72 //a list of the translations of the game available.
73 std::vector<language_def> get_languages();
74 
75 //function which, given the main configuration object, and a locale,
76 //will set string_table to be populated with data from that locale.
77 //locale may be either the full name of the language, like 'English',
78 //or the 2-letter version, like 'en'.
79 void set_language(const language_def& locale);
80 
81 //function which returns the name of the language currently used
82 const language_def& get_language();
84 
85 //function which attempts to query and return the locale on the system
86 const language_def& get_locale();
87 
88 /** Initializes the list of textdomains from a configuration object */
89 void init_textdomains(const config& cfg);
90 
91 /** Initializes certain English strings */
92 bool init_strings(const config& cfg);
93 
94 bool load_language_list();
95 
96 #endif
void init_textdomains(const config &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:293
const t_string & operator[](const std::string &key) const
Definition: language.cpp:73
bool operator<(const language_def &a) const
Definition: language.hpp:52
STL namespace.
std::vector< language_def > get_languages()
Definition: language.cpp:118
bool operator==(const language_def &) const
Definition: language.cpp:60
bool init_strings(const config &cfg)
Initializes certain English strings.
Definition: language.cpp:316
std::string localename
Definition: language.hpp:46
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
language_def(const std::string &name, const t_string &lang, const std::string &dir, const std::string &salternates="", const std::string &sort_name="")
Definition: language.hpp:36
bool load_language_list()
Definition: language.cpp:94
std::vector< language_def > language_list
Definition: language.hpp:56
void set_language(const language_def &locale)
Definition: language.cpp:211
const language_def & get_language()
Definition: language.cpp:251
t_string language
Definition: language.hpp:48
GLuint const GLchar * name
Definition: glew.h:1782
symbol_table string_table
Definition: language.cpp:65
const language_def & get_locale()
Definition: language.cpp:253
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
std::string sort_name
Definition: language.hpp:49
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
bool current_language_rtl()
Definition: language.cpp:55
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool & time_locale_correct()
Definition: language.cpp:67
std::vector< std::string > alternates
Definition: language.hpp:47