1 // tinygettext - A gettext replacement that works directly on .po files
2 // Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.de>
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #ifndef HEADER_TINYGETTEXT_LANGUAGE_HPP
19 #define HEADER_TINYGETTEXT_LANGUAGE_HPP
23 namespace tinygettext {
27 /** Lightweight wrapper around LanguageSpec */
31 LanguageSpec* language_spec;
33 Language(LanguageSpec* language_spec);
36 /** Create a language from language and country code:
37 Example: Languge("de", "DE"); */
38 static Language from_spec(const std::string& language,
39 const std::string& country = std::string(),
40 const std::string& modifier = std::string());
42 /** Create a language from language and country code:
43 Example: Languge("deutsch");
44 Example: Languge("de_DE"); */
45 static Language from_name(const std::string& str);
47 /** Create a language from an environment variable style string (e.g de_DE.UTF-8@modifier) */
48 static Language from_env(const std::string& env);
50 /** Compares two Languages, returns 0 on missmatch and a score
51 between 1 and 9 on match, the higher the score the better the
53 static int match(const Language& lhs, const Language& rhs);
55 /** Create an undefined Language object */
58 operator bool() const { return language_spec; }
60 /** Returns the language code (i.e. de, en, fr) */
61 std::string get_language() const;
63 /** Returns the country code (i.e. DE, AT, US) */
64 std::string get_country() const;
66 /** Returns the modifier of the language (i.e. latn or Latn for
67 Serbian with non-cyrilic characters) */
68 std::string get_modifier() const;
70 /** Returns the human readable name of the Language */
71 std::string get_name() const;
73 /** Returns the Language as string in the form of an environment
74 variable: {language}_{country}@{modifier} */
75 std::string str() const;
77 bool operator==(const Language& rhs);
78 bool operator!=(const Language& rhs);
80 friend bool operator<(const Language& lhs, const Language& rhs);
83 inline bool operator<(const Language& lhs, const Language& rhs) {
84 return lhs.language_spec < rhs.language_spec;
87 } // namespace tinygettext