90eccc1d408b7371cf163d252de1f0b664068f10
[supertux.git] / external / tinygettext / tinygettext / language.hpp
1 //  tinygettext - A gettext replacement that works directly on .po files
2 //  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.de>
3 //
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.
8 //
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.
13 //
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.
17
18 #ifndef HEADER_TINYGETTEXT_LANGUAGE_HPP
19 #define HEADER_TINYGETTEXT_LANGUAGE_HPP
20
21 #include <string>
22
23 namespace tinygettext {
24
25 struct LanguageSpec;
26
27 /** Lightweight wrapper around LanguageSpec */
28 class Language
29 {
30 private:
31   LanguageSpec* language_spec;
32
33   Language(LanguageSpec* language_spec);
34
35 public:
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());
41
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);
46
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);
49
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
52       match */
53   static int match(const Language& lhs, const Language& rhs);
54
55   /** Create an undefined Language object */
56   Language();
57   
58   operator bool() const { return language_spec; }
59
60   /** Returns the language code (i.e. de, en, fr) */
61   std::string get_language() const;
62
63   /** Returns the country code (i.e. DE, AT, US) */
64   std::string get_country()  const;
65
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;
69
70   /** Returns the human readable name of the Language */
71   std::string get_name() const;
72
73   /** Returns the Language as string in the form of an environment
74       variable: {language}_{country}@{modifier} */
75   std::string str() const;
76
77   bool operator==(const Language& rhs);
78   bool operator!=(const Language& rhs);
79
80   friend bool operator<(const Language& lhs, const Language& rhs);
81 };
82
83 inline bool operator<(const Language& lhs, const Language& rhs) {
84   return lhs.language_spec < rhs.language_spec;
85 }
86
87 } // namespace tinygettext
88
89 #endif
90
91 /* EOF */