Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
translation.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2017 Nore, Nathanaƫlle Courant <nore@mesecons.net>
4
5#pragma once
6
8#include <unordered_map>
9#include <map>
10#include <optional>
11#include <string>
12#include <vector>
13#include "config.h"
14
15class Translations;
17
19{
20public:
21 void loadTranslation(const std::string &filename, const std::string &data);
22 void clear();
23 const std::wstring &getTranslation(
24 const std::wstring &textdomain, const std::wstring &s) const;
25 const std::wstring &getPluralTranslation(const std::wstring &textdomain,
26 const std::wstring &s, unsigned long int number) const;
27 static const std::string_view getFileLanguage(const std::string &filename);
28 static inline bool isTranslationFile(const std::string &filename)
29 {
30 return getFileLanguage(filename) != "";
31 }
32 // for testing
33 inline size_t size()
34 {
35 return m_translations.size() + m_plural_translations.size()/2;
36 }
37
38private:
39 std::unordered_map<std::wstring, std::wstring> m_translations;
40 std::unordered_map<std::wstring, std::pair<GettextPluralForm::Ptr, std::vector<std::wstring>>> m_plural_translations;
41
42 void addTranslation(const std::wstring &textdomain, const std::wstring &original,
43 const std::wstring &translated);
44 void addPluralTranslation(const std::wstring &textdomain,
45 const GettextPluralForm::Ptr &plural,
46 const std::wstring &original,
47 std::vector<std::wstring> &translated);
48 std::wstring unescapeC(const std::wstring &str);
49 std::optional<std::pair<std::wstring, std::wstring>> parsePoLine(const std::string &line);
50 bool inEscape(const std::wstring &str, size_t pos);
51 void loadPoEntry(const std::wstring &basefilename, const GettextPluralForm::Ptr &plural_form, const std::map<std::wstring, std::wstring> &entry);
52 void loadMoEntry(const std::wstring &basefilename, const GettextPluralForm::Ptr &plural_form, const std::string &original, const std::string &translated);
53 void loadTrTranslation(const std::string &data);
54 void loadPoTranslation(const std::string &basefilename, const std::string &data);
55 void loadMoTranslation(const std::string &basefilename, const std::string &data);
56};
std::shared_ptr< GettextPluralForm > Ptr
Definition gettext_plural_form.h:14
Definition translation.h:19
std::wstring unescapeC(const std::wstring &str)
Definition translation.cpp:199
size_t size()
Definition translation.h:33
const std::wstring & getPluralTranslation(const std::wstring &textdomain, const std::wstring &s, unsigned long int number) const
Definition translation.cpp:49
static const std::string_view getFileLanguage(const std::string &filename)
Definition translation.cpp:21
void loadMoTranslation(const std::string &basefilename, const std::string &data)
Definition translation.cpp:552
void clear()
Definition translation.cpp:33
void addTranslation(const std::wstring &textdomain, const std::wstring &original, const std::wstring &translated)
Definition translation.cpp:67
const std::wstring & getTranslation(const std::wstring &textdomain, const std::wstring &s) const
Definition translation.cpp:39
void loadTrTranslation(const std::string &data)
Definition translation.cpp:94
std::unordered_map< std::wstring, std::wstring > m_translations
Definition translation.h:39
bool inEscape(const std::wstring &str, size_t pos)
Definition translation.cpp:355
void loadTranslation(const std::string &filename, const std::string &data)
Definition translation.cpp:629
void addPluralTranslation(const std::wstring &textdomain, const GettextPluralForm::Ptr &plural, const std::wstring &original, std::vector< std::wstring > &translated)
Definition translation.cpp:76
void loadMoEntry(const std::wstring &basefilename, const GettextPluralForm::Ptr &plural_form, const std::string &original, const std::string &translated)
Definition translation.cpp:514
static bool isTranslationFile(const std::string &filename)
Definition translation.h:28
std::unordered_map< std::wstring, std::pair< GettextPluralForm::Ptr, std::vector< std::wstring > > > m_plural_translations
Definition translation.h:40
void loadPoEntry(const std::wstring &basefilename, const GettextPluralForm::Ptr &plural_form, const std::map< std::wstring, std::wstring > &entry)
Definition translation.cpp:321
std::optional< std::pair< std::wstring, std::wstring > > parsePoLine(const std::string &line)
Definition translation.cpp:369
void loadPoTranslation(const std::string &basefilename, const std::string &data)
Definition translation.cpp:418
Translations * g_client_translations
Definition translation.cpp:18