API Documentation
Loading...
Searching...
No Matches
Translator.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Translator
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/String.h>
35#include <NDEVR/INIFactory.h>
36#include <NDEVR/File.h>
37#include <NDEVR/Dictionary.h>
38#include <NDEVR/INIInterface.h>
39namespace NDEVR
40{
41 /**--------------------------------------------------------------------------------------------------
42 \brief Contains logic for translating a string into a defined language
43 **/
45 {
46 public:
48 Translator(const String& translation_id);
49 Translator(const File& settings_file);
50 Translator(const Translator& translator);
51 virtual String convertNumber(const String& number_string, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits) const;
52 virtual String convertText(const String& text_string) const;
53 virtual String convertText(const String& text_string, const String& default_text) const;
54 void copyFrom(const Translator& trans, bool use_existing_ini_file);
55 void copyTranslationsFrom(const Translator& trans);
56 File translatorFile(bool user_file) const;
57 void getINI(INIFactory& factory) override;
60 const String& id() const { return m_translation_id; }
61 const String& name() const { return m_language_name; }
62 void setID(const String& id);
63 bool isLeftToRight() const;
64 void setName(const String& name);
65 Translator& operator=(const Translator& translation);
67 void saveTranslation(File location = File());
70 public:
72 static void SetMainTranslator(Translator* translator);
73 static String DefaultLabel(const String& text_string);
74 protected:
76 void init();
83 char m_number_sep;//typically ,
84 char m_decimal_sep;//typically .
85 bool m_left_to_right;//typically true
86 public:
88 };
89 //Translate string
90 #define _t(english_string) (TranslatedString(Translator::DefaultLabel(english_string), english_string))
91 //Translate number
92 #define _tn(number_string, add_comma, min_decimals, max_decimals, min_digits) (Translator::MainTranslator()->convertNumber(number_string, add_comma, min_decimals, max_decimals, min_digits))
93 //Translate string by description
94 #define _td(def, english_string) (TranslatedString(Translator::DefaultLabel(def), english_string))
95}
96
#define NDEVR_BASE_API
Definition DLLInfo.h:57
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
Contains methods for easily reading and writing to an INI file including efficient casting,...
Definition INIReader.h:68
Contains methods for easily reading and writing to an INI file including.
Definition INIInterface.h:45
A core part of the engine, stores variables that can be listened to with ResourceListener which will ...
Definition Toggle.h:41
The core String class for the NDEVR API.
Definition String.h:69
Contains logic for translating a string into a defined language.
Definition Translator.h:45
void setID(const String &id)
Translator(const String &translation_id)
File activeTranslatorFile() const
static void SetMainTranslator(Translator *translator)
void copyTranslationsFrom(const Translator &trans)
INIFactory & translationINI() const
void getINI(INIFactory &factory) override
bool m_has_loaded_language
Definition Translator.h:82
Translator & operator=(const Translator &translation)
bool isLeftToRight() const
String m_translation_id
Definition Translator.h:81
Translator(const Translator &translator)
Dictionary< String, String > translatedStrings() const
File m_translation_file
Definition Translator.h:78
virtual String convertNumber(const String &number_string, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits) const
INIFactory m_language_ini
Definition Translator.h:77
File translatorFile(bool user_file) const
const String & id() const
Definition Translator.h:60
char m_decimal_sep
Definition Translator.h:84
bool m_left_to_right
Definition Translator.h:85
String m_language_name
Definition Translator.h:79
void setName(const String &name)
virtual String convertText(const String &text_string, const String &default_text) const
static String DefaultLabel(const String &text_string)
static Resource< Translator * > main_translator
Definition Translator.h:87
String m_common_characters
Definition Translator.h:80
void copyFrom(const Translator &trans, bool use_existing_ini_file)
void saveTranslation(File location=File())
static Translator * MainTranslator()
char m_number_sep
Definition Translator.h:83
virtual String convertText(const String &text_string) const
const String & name() const
Definition Translator.h:61
String commonCharacters() const
void ensureLanguageLoaded() const
Translator(const File &settings_file)
static Dictionary< String, Translator > GetAvailableTranslations(File folder=File())
Definition ACIColor.h:37
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96