当前位置: 首页>>代码示例>>C++>>正文


C++ DictionaryManager类代码示例

本文整理汇总了C++中DictionaryManager的典型用法代码示例。如果您正苦于以下问题:C++ DictionaryManager类的具体用法?C++ DictionaryManager怎么用?C++ DictionaryManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DictionaryManager类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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);
        }
      }

//.........这里部分代码省略.........
开发者ID:SuperTux,项目名称:tinygettext,代码行数:101,代码来源:tinygettext_test.cpp

示例2: 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() );
}
开发者ID:rjc862003,项目名称:Unvanquished,代码行数:34,代码来源:translation.cpp

示例3: Trans_ReturnLanguage

/*
====================
Trans_ReturnLanguage

Return a loaded language. If desired language is not found, return closest match. 
If no languages are close, force English.
====================
*/
Language Trans_ReturnLanguage( const char *lang )
{
    int bestScore = 0;
    Language bestLang, language = Language::from_env( std::string( lang ) );
    
    std::set<Language> langs = trans_manager.get_languages();
    for( std::set<Language>::iterator i = langs.begin(); i != langs.end(); i++ )
    {
        int score = Language::match( language, *i );
        
        if( score > bestScore )
        {
            bestScore = score;
            bestLang = *i;
        }
    }
    
    // Return "en" if language not found
    if( !bestLang )
    {
        Com_Printf( _("^3WARNING:^7 Language \"%s\" (%s) not found. Default to \"English\" (en)\n"),
                    language.get_name().empty() ? _("Unknown Language") : language.get_name().c_str(),
                    lang );
        bestLang = Language::from_env( "en" );
    }
    
    return bestLang;
}
开发者ID:Sixthly,项目名称:Unvanquished,代码行数:36,代码来源:translation.cpp

示例4: 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
}
开发者ID:Sixthly,项目名称:Unvanquished,代码行数:17,代码来源:translation.cpp

示例5: Trans_Init

/*
============
Trans_Init
============
*/
void Trans_Init( void )
{
    char langList[ MAX_TOKEN_CHARS ] = "";
    char encList[ MAX_TOKEN_CHARS ] = "";
    std::set<Language>  langs;
    Language            lang;

    Cmd_AddCommand( "updatelanguage", Trans_UpdateLanguage_f );

    language = Cvar_Get( "language", "", CVAR_ARCHIVE );
    trans_debug = Cvar_Get( "trans_debug", "0", CVAR_ARCHIVE );
    trans_languages = Cvar_Get( "trans_languages", "", CVAR_ROM );
    trans_encodings = Cvar_Get( "trans_encodings", "", CVAR_ROM );

    // set tinygettext log callbacks
    Log::set_log_error_callback( &Trans_Error );
    Log::set_log_warning_callback( &Trans_Warning );
    Log::set_log_info_callback( &Trans_Info );

    trans_manager.set_filesystem( std::auto_ptr<FileSystem>( new DaemonFileSystem ) );
    trans_managergame.set_filesystem( std::auto_ptr<FileSystem>( new DaemonFileSystem ) );

    trans_manager.add_directory( "translation/client" );
    trans_managergame.add_directory( "translation/game" );

    langs = trans_manager.get_languages();

    for( std::set<Language>::iterator p = langs.begin(); p != langs.end(); p++ )
    {
        Q_strcat( langList, sizeof( langList ), va( "\"%s\" ", p->get_name().c_str() ) );
        Q_strcat( encList, sizeof( encList ), va( "\"%s%s%s\" ", p->get_language().c_str(),
                                                  p->get_country().c_str()[0] ? "_" : "",
                                                  p->get_country().c_str() ) );
    }

    Cvar_Set( "trans_languages", langList );
    Cvar_Set( "trans_encodings", encList );

    Com_Printf( P_( "Loaded %u language\n", "Loaded %u languages\n", langs.size() ), ( int )langs.size() );
}
开发者ID:rjc862003,项目名称:Unvanquished,代码行数:45,代码来源:translation.cpp

示例6: sizeof

/*
============
Trans_Init
============
*/
extern "C" void Trans_Init( void )
{
    char langList[ MAX_TOKEN_CHARS ] = "";
    char encList[ MAX_TOKEN_CHARS ] = "";
    FL_Locale           *locale;
    std::set<Language>  langs;
    Language            lang;

    Cmd_AddCommand( "updatelanguage", Trans_UpdateLanguage_f );

    language = Cvar_Get( "language", "", CVAR_ARCHIVE );
    trans_debug = Cvar_Get( "trans_debug", "0", CVAR_ARCHIVE );
    trans_languages = Cvar_Get( "trans_languages", "", CVAR_ROM );
    trans_encodings = Cvar_Get( "trans_encodings", "", CVAR_ROM );

    // set tinygettext log callbacks
    Log::set_log_error_callback( &Trans_Error );
    Log::set_log_warning_callback( &Trans_Warning );
    Log::set_log_info_callback( &Trans_Info );

    trans_manager.set_filesystem( std::auto_ptr<FileSystem>( new DaemonFileSystem ) );
    trans_managergame.set_filesystem( std::auto_ptr<FileSystem>( new DaemonFileSystem ) );

    trans_manager.add_directory( "translation/client" );
    trans_managergame.add_directory( "translation/game" );

    langs = trans_manager.get_languages();

    for( std::set<Language>::iterator p = langs.begin(); p != langs.end(); p++ )
    {
        Q_strcat( langList, sizeof( langList ), va( "\"%s\" ", p->get_name().c_str() ) );
        Q_strcat( encList, sizeof( encList ), va( "\"%s%s%s\" ", p->get_language().c_str(),
                                                  p->get_country().c_str()[0] ? "_" : "",
                                                  p->get_country().c_str() ) );
    }

    Cvar_Set( "trans_languages", langList );
    Cvar_Set( "trans_encodings", encList );

    // Only detect locale if no previous language set.
    if( !language->string[0] )
    {
        FL_FindLocale( &locale, FL_MESSAGES );

        // Invalid or not found. Just use builtin language.
        if( !locale->lang || !locale->lang[0] || !locale->country || !locale->country[0] )
        {
            Cvar_Set( "language", "en" );
        }
        else
        {
            Cvar_Set( "language", va( "%s%s%s", locale->lang,
                                      locale->country[0] ? "_" : "",
                                      locale->country ) );
        }

        FL_FreeLocale( &locale );
    }

    Trans_SetLanguage( language->string );

    Com_Printf( P_( "Loaded %u language\n", "Loaded %u languages\n", langs.size() ), ( int )langs.size() );
}
开发者ID:ZdrytchX,项目名称:Unvanquished-KoRx,代码行数:68,代码来源:translation.cpp

示例7: ss

/*
============
Trans_Init
============
*/
extern "C" void Trans_Init( void )
{
    char                **poFiles, langList[ MAX_TOKEN_CHARS ] = "", encList[ MAX_TOKEN_CHARS ] = "";
    int                 numPoFiles, i;
    FL_Locale           *locale;
    std::set<Language>  langs;
    Language            lang;
    
    language = Cvar_Get( "language", "", CVAR_ARCHIVE );
    language_debug = Cvar_Get( "language_debug", "0", CVAR_ARCHIVE );
    trans_languages = Cvar_Get( "trans_languages", "", CVAR_ROM );
    trans_encodings = Cvar_Get( "trans_languages", "", CVAR_ROM );
    
    // Only detect locale if no previous language set.
    if( !language->string[0] )
    {
        FL_FindLocale( &locale, FL_MESSAGES );
        
        // Invalid or not found. Just use builtin language.
        if( !locale->lang || !locale->lang[0] || !locale->country || !locale->country[0] ) 
        {
            Cvar_Set( "language", "en" );
        }
        else
        {
            Cvar_Set( "language", va( "%s%s%s", locale->lang, 
                                      locale->country[0] ? "_" : "",
                                      locale->country ) );
        }
    }
    
    poFiles = FS_ListFiles( "translation/client", ".po", &numPoFiles );
    
    // This assumes that the filenames in both folders are the same
    for( i = 0; i < numPoFiles; i++ )
    {
        int ret;
        char *buffer, language[ 6 ];
        
        if( FS_ReadFile( va( "translation/client/%s", poFiles[ i ] ), ( void ** ) &buffer ) > 0 )
        {
            COM_StripExtension2( poFiles[ i ], language, sizeof( language ) );
            std::stringstream ss( buffer );
            trans_manager.add_po( poFiles[ i ], ss, Language::from_env( std::string( language ) ) );
            FS_FreeFile( buffer );
        }
        else
        {
            Com_Printf(_( "^1ERROR: Could not open client translation: %s\n"), poFiles[ i ] );
        }
        
        if( FS_ReadFile( va( "translation/game/%s", poFiles[ i ] ), ( void ** ) &buffer ) > 0 )
        {
            COM_StripExtension2( poFiles[ i ], language, sizeof( language ) );
            std::stringstream ss( buffer );
            trans_managergame.add_po( poFiles[ i ], ss, Language::from_env( std::string( language ) ) );
            FS_FreeFile( buffer );
        }
        else
        {
            Com_Printf(_( "^1ERROR: Could not open game translation: %s\n"), poFiles[ i ] );
        }
    }
    FS_FreeFileList( poFiles );
    langs = trans_manager.get_languages();
    for( std::set<Language>::iterator p = langs.begin(); p != langs.end(); p++ )
    {
        Q_strcat( langList, sizeof( langList ), va( "\"%s\" ", p->get_name().c_str() ) );
        Q_strcat( encList, sizeof( encList ), va( "\"%s%s%s\" ", p->get_language().c_str(), 
                                                  p->get_country().c_str()[0] ? "_" : "",
                                                  p->get_country().c_str() ) );
    }
    Cvar_Set( "trans_languages", langList );
    Cvar_Set( "trans_encodings", encList );
    Com_Printf(_( "Loaded %lu language(s)\n"), langs.size() );
    Cmd_AddCommand( "updatelanguage", Trans_UpdateLanguage_f );
    if( langs.size() )
    {
        lang = Trans_ReturnLanguage( language->string );
        trans_dict = trans_manager.get_dictionary( lang );
        trans_dictgame = trans_managergame.get_dictionary( lang );
        enabled = true;
    }
}
开发者ID:Sixthly,项目名称:Unvanquished,代码行数:89,代码来源:translation.cpp


注:本文中的DictionaryManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。