FlightGear next
FGTranslate.hxx
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Florent Rougon
2// SPDX-License-Identifier: GPL-2.0-or-later
3
8
9#pragma once
10
11#include <cstddef>
12#include <memory>
13#include <string>
14#include <vector>
15
16#include "LanguageInfo.hxx"
17#include "TranslationDomain.hxx"
18
78
80{
81public:
82 // I did this to avoid making both LanguageInfo and FGTranslate class
83 // templates...
85
96 explicit FGTranslate(const std::string& domain = "core");
97
108 FGTranslate& setDomain(const std::string& domain);
109
119 getResource(const std::string& resourceName) const;
120
143 std::string get(const std::string& resource, const std::string& basicId,
144 int index = 0) const;
155 std::string getPlural(intType cardinalNumber, const std::string& resource,
156 const std::string& basicId, int index = 0) const;
169 std::string getWithDefault(const std::string& resource,
170 const std::string& basicId,
171 const std::string& defaultValue,
172 int index = 0) const;
184 std::string getPluralWithDefault(
185 intType cardinalNumber, const std::string& resource,
186 const std::string& basicId, const std::string& defaultValue,
187 int index = 0) const;
188
197 std::vector<std::string> getAll(const std::string& resource,
198 const std::string& basicId) const;
208 std::size_t getCount(const std::string& resource,
209 const std::string& basicId) const;
210
223 std::shared_ptr<TranslationUnit>
224 translationUnit(const std::string& resource, const std::string& basicId,
225 int index = 0) const;
229 static void setupGhost();
230
231private:
232 using TranslationDomain = flightgear::TranslationDomain;
233
234 using TranslationDomainRef = std::shared_ptr<const TranslationDomain>;
235 TranslationDomainRef _domain;
236};
Information on plural forms for the supported languages.
Container for all TranslationResource's belonging to a domain.
flightgear::LanguageInfo::intType intType
std::vector< std::string > getAll(const std::string &resource, const std::string &basicId) const
Get all translations associated to an id (tag name).
FGTranslate(const std::string &domain="core")
Constructor.
std::size_t getCount(const std::string &resource, const std::string &basicId) const
Get the number of translatable strings with a given id (tag name).
std::string getPluralWithDefault(intType cardinalNumber, const std::string &resource, const std::string &basicId, const std::string &defaultValue, int index=0) const
Same as getWithDefault(), but for a string that has plural forms.
std::string getPlural(intType cardinalNumber, const std::string &resource, const std::string &basicId, int index=0) const
Same as get(), but for a string that has plural forms.
static void setupGhost()
Set up a Nasal type that wraps FGTranslate.
flightgear::TranslationDomain::ResourceRef getResource(const std::string &resourceName) const
Get the specified resource.
std::string getWithDefault(const std::string &resource, const std::string &basicId, const std::string &defaultValue, int index=0) const
Get a single translation, with default for missing or empty strings.
std::string get(const std::string &resource, const std::string &basicId, int index=0) const
Get a single translation.
std::shared_ptr< TranslationUnit > translationUnit(const std::string &resource, const std::string &basicId, int index=0) const
Return a shared pointer to a TranslationUnit.
FGTranslate & setDomain(const std::string &domain)
Change the domain from which to retrieve translations.
Class that holds translation resources within a domain.
std::shared_ptr< TranslationResource > ResourceRef