~ubuntu-branches/ubuntu/raring/simutrans/raring-proposed

« back to all changes in this revision

Viewing changes to dataobj/translator.h

  • Committer: Package Import Robot
  • Author(s): Ansgar Burchardt
  • Date: 2011-11-03 19:59:02 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20111103195902-uopgwf488mfctb75
Tags: 111.0-1
* New upstream release.
* debian/rules: Update get-orig-source target for new upstream release.
* Use xz compression for source and binary packages.
* Use override_* targets to simplify debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#include <stdio.h>
11
11
#include <string>
12
12
#include "../tpl/stringhashtable_tpl.h"
 
13
#include "../tpl/vector_tpl.h"
13
14
 
14
15
 
15
16
/**
23
24
 */
24
25
class translator
25
26
{
26
 
        private:
27
 
                //cannot be instantiated outside translator
28
 
                translator() { current_lang = -1; }
29
 
 
30
 
                int current_lang;
31
 
                int lang_count;
32
 
 
33
 
                /* The single instance that this class will use to gain access to
34
 
                 * the member variables such as language names
35
 
                 */
36
 
                static translator single_instance;
37
 
 
38
 
                /* Methods related to loading a language file into memory */
39
 
                static void load_language_file(FILE* file);
40
 
                static void load_language_iso(const std::string &iso);
41
 
 
42
 
        public:
43
 
                struct lang_info {
44
 
                        const char* translate(const char* text) const;
45
 
 
46
 
                        stringhashtable_tpl<const char*> texts;
47
 
                        const char* name;
48
 
                        const char* iso;
49
 
                        const char* iso_base;
50
 
                        bool utf_encoded;
51
 
                };
52
 
 
53
 
                static void init_city_names(int lang);
54
 
                static const char* get_city_name(uint nr); ///< return a random city name
55
 
                static int get_count_city_name(void);
56
 
 
57
 
                /**
58
 
                 * Loads up all files of language type from the 'language' directory.
59
 
                 * This method must be called for languages to be loaded up, undefined
60
 
                 * behaviour may follow if calls to translate message or similar are
61
 
                 * called before load has been called
62
 
                 */
63
 
                static bool load(const std::string &scenario_path);
64
 
 
65
 
                /**
66
 
                 * Get/Set the currently selected language, based on the
67
 
                 * index number
68
 
                 */
69
 
                static int get_language() {
70
 
                        return single_instance.current_lang;
71
 
                }
72
 
 
73
 
                // returns the id for this language or -1 if not there
74
 
                static int get_language(const char* iso);
75
 
 
76
 
                /** Get information about the currently selected language */
77
 
                static const lang_info* get_lang();
78
 
 
79
 
                static const lang_info* get_langs();
80
 
 
81
 
                /**
82
 
                 * First checks to see whether the language is in bounds, will
83
 
                 * then change what language is being used, otherwise prints
84
 
                 * an error message, leaving the language as it is
85
 
                 */
86
 
                static void set_language(int lang);
87
 
                static void set_language(const char* iso);
88
 
 
89
 
                /**
90
 
                 * Returns the number of loaded languages.
91
 
                 */
92
 
                static int get_language_count() { return single_instance.lang_count; }
93
 
 
94
 
                /**
95
 
                 * Translates a given string(key) to its locale
96
 
                 * specific counterpart, using the current language
97
 
                 * table.
98
 
                 * the second variant just uses the language with the index
99
 
                 * @return translated string, (null) if string is null,
100
 
                 * or the string if the translation is not found
101
 
                 */
102
 
                static const char *translate(const char* str);
103
 
                static const char *translate(const char* str, int lang);
104
 
 
105
 
                /**
106
 
                 * @return replacement info for almost any object within the game
107
 
                 */
108
 
                static const char *compatibility_name(const char* str);
109
 
 
110
 
                // return the name of the month
111
 
                static const char *get_month_name(uint16 month);
 
27
private:
 
28
        //cannot be instantiated outside translator
 
29
        translator() { current_lang = -1; }
 
30
 
 
31
        int current_lang;
 
32
        int lang_count;
 
33
 
 
34
        /* The single instance that this class will use to gain access to
 
35
         * the member variables such as language names
 
36
         */
 
37
        static translator single_instance;
 
38
 
 
39
        /* Methods related to loading a language file into memory */
 
40
        static void load_language_file(FILE* file);
 
41
        static void load_language_iso(const std::string &iso);
 
42
 
 
43
        static vector_tpl<char*> city_name_list;
 
44
        static vector_tpl<char*> street_name_list;
 
45
 
 
46
        static void load_custom_list( int lang, vector_tpl<char*> &name_list, const char *fileprefix );
 
47
 
 
48
public:
 
49
        struct lang_info {
 
50
                const char* translate(const char* text) const;
 
51
 
 
52
                stringhashtable_tpl<const char*> texts;
 
53
                const char* name;
 
54
                const char* iso;
 
55
                const char* iso_base;
 
56
                bool utf_encoded;
 
57
        };
 
58
 
 
59
        static void init_custom_names(int lang);
 
60
 
 
61
        static const vector_tpl<char*> &get_city_name_list() { return city_name_list; }
 
62
        static const vector_tpl<char*> &get_street_name_list() { return street_name_list; }
 
63
 
 
64
        /**
 
65
         * Loads up all files of language type from the 'language' directory.
 
66
         * This method must be called for languages to be loaded up, undefined
 
67
         * behaviour may follow if calls to translate message or similar are
 
68
         * called before load has been called
 
69
         */
 
70
        static bool load(const std::string &scenario_path);
 
71
 
 
72
        /**
 
73
         * Get/Set the currently selected language, based on the
 
74
         * index number
 
75
         */
 
76
        static int get_language() {
 
77
                return single_instance.current_lang;
 
78
        }
 
79
 
 
80
        // returns the id for this language or -1 if not there
 
81
        static int get_language(const char* iso);
 
82
 
 
83
        /** Get information about the currently selected language */
 
84
        static const lang_info* get_lang();
 
85
 
 
86
        static const lang_info* get_langs();
 
87
 
 
88
        /**
 
89
         * First checks to see whether the language is in bounds, will
 
90
         * then change what language is being used, otherwise prints
 
91
         * an error message, leaving the language as it is
 
92
         */
 
93
        static void set_language(int lang);
 
94
        static void set_language(const char* iso);
 
95
 
 
96
        /**
 
97
         * Returns the number of loaded languages.
 
98
         */
 
99
        static int get_language_count() { return single_instance.lang_count; }
 
100
 
 
101
        /**
 
102
         * Translates a given string(key) to its locale
 
103
         * specific counterpart, using the current language
 
104
         * table.
 
105
         * the second variant just uses the language with the index
 
106
         * @return translated string, (null) if string is null,
 
107
         * or the string if the translation is not found
 
108
         */
 
109
        static const char *translate(const char* str);
 
110
        static const char *translate(const char* str, int lang);
 
111
 
 
112
        /**
 
113
         * @return replacement info for almost any object within the game
 
114
         */
 
115
        static const char *compatibility_name(const char* str);
 
116
 
 
117
        // return the name of the month
 
118
        static const char *get_month_name(uint16 month);
112
119
};
113
120
 
114
121
#endif