本文整理汇总了C++中Language::get_name方法的典型用法代码示例。如果您正苦于以下问题:C++ Language::get_name方法的具体用法?C++ Language::get_name怎么用?C++ Language::get_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Language
的用法示例。
在下文中一共展示了Language::get_name方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Trans_SetLanguage
void Trans_SetLanguage( const char* lang )
{
Language requestLang = Language::from_env( std::string( lang ) );
// default to english
Language bestLang = Language::from_env( "en" );
int bestScore = Language::match( requestLang, bestLang );
std::set<Language> langs = trans_manager.get_languages();
for( std::set<Language>::iterator i = langs.begin(); i != langs.end(); i++ )
{
int score = Language::match( requestLang, *i );
if( score > bestScore )
{
bestScore = score;
bestLang = *i;
}
}
// language not found, display warning
if( bestScore == 0 )
{
Com_Printf( S_WARNING "Language \"%s\" (%s) not found. Default to \"English\" (en)\n",
requestLang.get_name().empty() ? "Unknown Language" : requestLang.get_name().c_str(),
lang );
}
trans_manager.set_language( bestLang );
trans_managergame.set_language( bestLang );
Com_Printf( _( "Set language to %s\n" ), bestLang.get_name().c_str() );
}
示例2: strlen
extern "C" void Trans_UpdateLanguage_f( void )
{
if( !enabled ) { return; }
Language lang = Trans_ReturnLanguage( language->string );
trans_dict = trans_manager.get_dictionary( lang );
trans_dictgame = trans_managergame.get_dictionary( lang );
Com_Printf(_( "Switched language to %s\n"), lang.get_name().c_str() );
#ifndef DEDICATED
// update the default console keys string
extern cvar_t *cl_consoleKeys; // should really #include client.h
Z_Free( cl_consoleKeys->resetString );
const char *default_consoleKeys = _("~ ` 0x7e 0x60");
cl_consoleKeys->resetString = (char *) Z_Malloc( strlen( default_consoleKeys ) + 1 );
strcpy( cl_consoleKeys->resetString, default_consoleKeys );
#endif
}
示例3: if
// ----------------------------------------------------------------------------
Translations::Translations() //: m_dictionary_manager("UTF-16")
{
m_dictionary_manager.add_directory(
file_manager->getAsset(FileManager::TRANSLATION,""));
if (g_language_list.size() == 0)
{
std::set<Language> languages = m_dictionary_manager.get_languages();
// English is always there but won't be found on file system
g_language_list.push_back("en");
std::set<Language>::iterator it;
for (it = languages.begin(); it != languages.end(); it++)
{
g_language_list.push_back((*it).str());
}
}
// LC_ALL does not work, sscanf will then not always be able
// to scan for example: s=-1.1,-2.3,-3.3 correctly, which is
// used in driveline files.
#if defined(WIN32) && !defined(__CYGWIN__)
// Windows does not have LC_MESSAGES
setlocale(LC_CTYPE, "");
#else
setlocale(LC_MESSAGES, "");
#endif
/*
bindtextdomain (PACKAGE, file_manager->getTranslationDir().c_str());
if (sizeof(wchar_t) == 4)
{
if (IS_LITTLE_ENDIAN) bind_textdomain_codeset(PACKAGE, "UTF-32LE");
else bind_textdomain_codeset(PACKAGE, "UTF-32BE");
}
else if (sizeof(wchar_t) == 2)
{
bind_textdomain_codeset(PACKAGE, "UTF-16LE");
}
else
{
fprintf(stderr, "Your wchar_t is neither 2 byte-long nor 4. What now??\n");
exit(1);
}
textdomain (PACKAGE);
*/
/*
const std::set<Language>& languages = m_dictionary_manager.get_languages();
Log::info("Translatings", "Number of languages: %d", languages.size());
for (std::set<Language>::const_iterator i = languages.begin();
i != languages.end(); ++i)
{
const Language& language = *i;
Log::info("Translatings", "Env: %s", language.str());
Log::info("Translatings", "Name: %s", language.get_name());
Log::info("Translatings", "Language: %s", language.get_language());
Log::info("Translatings", "Country: %s", language.get_country());
Log::info("Translatings", "Modifier: %s", language.get_modifier());
}
*/
const char *p_language = getenv("LANGUAGE");
std::string language;
if(p_language)
{
language=p_language;
}
else
{
const char *p_lang = getenv("LANG");
if(p_lang)
language = p_lang;
else
{
#ifdef WIN32
// Thanks to the frogatto developer for this code snippet:
char c[1024];
GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME,
c, 1024);
Log::verbose("translation", "GetLocaleInfo langname returns '%s'.",
c);
if(c[0])
{
language = c;
GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME,
c, 1024);
Log::verbose("translation",
"GetLocaleInfo tryname returns '%s'.", c);
if(c[0]) language += std::string("_")+c;
} // if c[0]
#endif
//.........这里部分代码省略.........
示例4: main
int main(int argc, char** argv)
{
try
{
if (argc == 3 && strcmp(argv[1], "language-dir") == 0)
{
DictionaryManager dictionary_manager;
dictionary_manager.add_directory(argv[2]);
const std::set<Language>& languages = dictionary_manager.get_languages();
std::cout << "Number of languages: " << languages.size() << std::endl;
for (std::set<Language>::const_iterator i = languages.begin(); i != languages.end(); ++i)
{
const Language& language = *i;
std::cout << "Env: " << language.str() << std::endl
<< "Name: " << language.get_name() << std::endl
<< "Language: " << language.get_language() << std::endl
<< "Country: " << language.get_country() << std::endl
<< "Modifier: " << language.get_modifier() << std::endl
<< std::endl;
}
}
else if (argc == 3 && strcmp(argv[1], "language") == 0)
{
const char* language_cstr = argv[2];
Language language = Language::from_name(language_cstr);
if (language)
std::cout << "Env: " << language.str() << std::endl
<< "Name: " << language.get_name() << std::endl
<< "Language: " << language.get_language() << std::endl
<< "Country: " << language.get_country() << std::endl
<< "Modifier: " << language.get_modifier() << std::endl;
else
std::cout << "not found" << std::endl;
}
else if (argc == 4 && strcmp(argv[1], "translate") == 0)
{
const char* filename = argv[2];
const char* message = argv[3];
Dictionary dict;
read_dictionary(filename, dict);
std::cout << "TRANSLATION: \"\"\"" << dict.translate(message) << "\"\"\""<< std::endl;
}
else if (argc == 5 && strcmp(argv[1], "translate") == 0)
{
const char* filename = argv[2];
const char* context = argv[3];
const char* message = argv[4];
Dictionary dict;
read_dictionary(filename, dict);
std::cout << dict.translate_ctxt(context, message) << std::endl;
}
else if (argc == 6 && strcmp(argv[1], "translate") == 0)
{
const char* filename = argv[2];
const char* message_singular = argv[3];
const char* message_plural = argv[4];
int num = atoi(argv[5]);
Dictionary dict;
read_dictionary(filename, dict);
std::cout << dict.translate_plural(message_singular, message_plural, num) << std::endl;
}
else if (argc == 7 && strcmp(argv[1], "translate") == 0)
{
const char* filename = argv[2];
const char* context = argv[3];
const char* message_singular = argv[4];
const char* message_plural = argv[5];
int num = atoi(argv[6]);
Dictionary dict;
read_dictionary(filename, dict);
std::cout << dict.translate_ctxt_plural(context, message_singular, message_plural, num) << std::endl;
}
else if ((argc == 4 || argc == 5) && strcmp(argv[1], "directory") == 0)
{
const char* directory = argv[2];
const char* message = argv[3];
const char* language = (argc == 5) ? argv[4] : NULL;
DictionaryManager manager;
manager.add_directory(directory);
if (language)
{
Language lang = Language::from_name(language);
if (lang)
{
manager.set_language(lang);
}
else
{
std::cout << "Unknown language: " << language << std::endl;
exit(EXIT_FAILURE);
}
}
//.........这里部分代码省略.........