15#include <simgear/debug/logstream.hxx>
16#include <simgear/nasal/cppbind/Ghost.hxx>
17#include <simgear/nasal/cppbind/NasalCallContext.hxx>
30 : _domain(
globals->get_locale()->getDomain(domain))
36 _domain =
globals->get_locale()->getDomain(domain);
44 return _domain->getResource(resourceName);
50std::shared_ptr<TranslationUnit>
57 return resource->translationUnit(basicId, index);
69 return resource->get(basicId, index);
76 const string& basicId,
int index)
const
81 return resource->getPlural(cardinalNumber, basicId, index);
88 const string& basicId,
89 const string& defaultValue,
int index)
const
94 return resource->getWithDefault(basicId, defaultValue, index);
101 intType cardinalNumber,
const string& resourceName,
const string& basicId,
102 const string& defaultValue,
int index)
const
107 return resource->getPluralWithDefault(cardinalNumber, basicId,
108 defaultValue, index);
115 const string& basicId)
const
120 return resource->getAll(basicId);
127 const string& basicId)
const
132 return resource->getCount(basicId);
140 if (ctx.argc < 2 || ctx.argc > 3) {
141 ctx.runtimeError(
"FGTranslate.get(resource, basicId[, index])");
144 const auto resource = ctx.requireArg<std::string>(0);
145 const auto basicId = ctx.requireArg<std::string>(1);
146 const auto index = ctx.getArg<
int>(2);
148 return ctx.to_nasal(tr.
get(std::move(resource), std::move(basicId),
154 if (ctx.argc < 3 || ctx.argc > 4) {
156 "FGTranslate.getPlural(cardinalNumber, resource, basicId[, index])");
160 const auto resource = ctx.requireArg<std::string>(1);
161 const auto basicId = ctx.requireArg<std::string>(2);
162 const auto index = ctx.getArg<
int>(3);
164 return ctx.to_nasal(tr.
getPlural(cardinalNumber, std::move(resource),
165 std::move(basicId), index));
169 const nasal::CallContext& ctx)
171 if (ctx.argc < 3 || ctx.argc > 4) {
172 ctx.runtimeError(
"FGTranslate.getWithDefault(resource, basicId, "
173 "defaultValue[, index])");
176 const auto resource = ctx.requireArg<std::string>(0);
177 const auto basicId = ctx.requireArg<std::string>(1);
178 const auto defaultValue = ctx.requireArg<std::string>(2);
179 const auto index = ctx.getArg<
int>(3);
183 std::move(defaultValue), index));
187 const nasal::CallContext& ctx)
189 if (ctx.argc < 4 || ctx.argc > 5) {
191 "FGTranslate.getPluralWithDefault(cardinalNumber, resource, "
192 "basicId, defaultValue[, index])");
196 const auto resource = ctx.requireArg<std::string>(1);
197 const auto basicId = ctx.requireArg<std::string>(2);
198 const auto defaultValue = ctx.requireArg<std::string>(3);
199 const auto index = ctx.getArg<
int>(4);
203 std::move(basicId), std::move(defaultValue),
208 const nasal::CallContext& ctx)
210 if (ctx.argc < 2 || ctx.argc > 3) {
212 "FGTranslate.translationUnit(resource, basicId[, index])");
215 const auto resource = ctx.requireArg<std::string>(0);
216 const auto basicId = ctx.requireArg<std::string>(1);
217 const auto index = ctx.getArg<
int>(2);
226 using FGTranslateRef = std::shared_ptr<FGTranslate>;
227 using NasalFGTranslate = nasal::Ghost<FGTranslateRef>;
229 NasalFGTranslate::init(
"FGTranslate")
231 .method(
"get", &
f_get)
static naRef f_getPlural(const FGTranslate &tr, const nasal::CallContext &ctx)
static naRef f_getWithDefault(const FGTranslate &tr, const nasal::CallContext &ctx)
static naRef f_translationUnit(const FGTranslate &tr, const nasal::CallContext &ctx)
static naRef f_getPluralWithDefault(const FGTranslate &tr, const nasal::CallContext &ctx)
static naRef f_get(const FGTranslate &tr, const nasal::CallContext &ctx)
Class for retrieving translated strings.
Container for all TranslationResource's belonging to a domain.
Class for retrieving translated strings.
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.
std::shared_ptr< TranslationResource > ResourceRef
Class that holds translation resources within a domain.
FlightGear Localization Support.