1 /* 2 mkvmerge -- utility for splicing together matroska files 3 from component media subtypes 4 5 Distributed under the GPL v2 6 see the file COPYING for details 7 or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 8 9 translation, locale handling 10 11 Written by Moritz Bunkus <moritz@bunkus.org>. 12 */ 13 14 #pragma once 15 16 #include "common/common_pch.h" 17 18 #include <ostream> 19 20 class translation_c { 21 public: 22 static std::vector<translation_c> ms_available_translations; 23 static int ms_active_translation_idx; 24 static std::string ms_default_iso639_ui_language; 25 26 public: 27 std::string m_iso639_alpha_3_code, m_unix_locale, m_windows_locale, m_windows_locale_sysname, m_english_name, m_translated_name; 28 bool m_line_breaks_anywhere; 29 int m_language_id, m_sub_language_id; 30 31 translation_c(std::string iso639_alpha_3_code, 32 std::string unix_locale, 33 std::string windows_locale, 34 std::string windows_locale_sysname, 35 std::string english_name, 36 std::string translated_name, 37 bool line_breaks_anywhere, 38 int language_id, 39 int sub_language_id); 40 41 std::string get_locale() const; 42 bool matches(std::string const &locale) const; 43 44 static void initialize_available_translations(); 45 static void initialize_std_locale(); 46 static int look_up_translation(const std::string &locale); 47 static int look_up_translation(int language_id, int sub_language_id); 48 static std::string get_default_ui_locale(); 49 static void determine_default_iso639_ui_language(); 50 static translation_c &get_active_translation(); 51 static void set_active_translation(const std::string &locale); 52 }; 53 54 class translatable_string_c { 55 protected: 56 std::vector<std::string> m_untranslated_strings; 57 std::optional<std::string> m_overridden_by; 58 59 public: 60 translatable_string_c() = default; 61 translatable_string_c(const std::string &untranslated_string); 62 translatable_string_c(const char *untranslated_string); 63 translatable_string_c(std::vector<translatable_string_c> const &untranslated_strings); 64 65 std::string get_translated() const; 66 std::string get_untranslated() const; 67 68 translatable_string_c &override(std::string const &by); 69 70 protected: 71 std::string join(std::vector<std::string> const &strings) const; 72 }; 73 74 #define YT(s) translatable_string_c(s) 75 76 inline std::ostream & 77 operator <<(std::ostream &out, 78 translatable_string_c const &s) { 79 out << s.get_translated(); 80 return out; 81 } 82 83 void init_locales(std::string locale = ""); 84