You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

130 lines
3.9 KiB

  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: indexfile.cc,v 1.2.2.1 2003/12/24 23:09:17 mdz Exp $
  4. /* ######################################################################
  5. Index File - Abstraction for an index of archive/souce file.
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include Files /*{{{*/
  9. #include <apt-pkg/configuration.h>
  10. #include <apt-pkg/indexfile.h>
  11. #include <apt-pkg/error.h>
  12. #include <clocale>
  13. #include <cstring>
  14. /*}}}*/
  15. // Global list of Item supported
  16. static pkgIndexFile::Type *ItmList[10];
  17. pkgIndexFile::Type **pkgIndexFile::Type::GlobalList = ItmList;
  18. unsigned long pkgIndexFile::Type::GlobalListLen = 0;
  19. // Type::Type - Constructor /*{{{*/
  20. // ---------------------------------------------------------------------
  21. /* */
  22. pkgIndexFile::Type::Type()
  23. {
  24. ItmList[GlobalListLen] = this;
  25. GlobalListLen++;
  26. }
  27. /*}}}*/
  28. // Type::GetType - Locate the type by name /*{{{*/
  29. // ---------------------------------------------------------------------
  30. /* */
  31. pkgIndexFile::Type *pkgIndexFile::Type::GetType(const char *Type)
  32. {
  33. for (unsigned I = 0; I != GlobalListLen; I++)
  34. if (strcmp(GlobalList[I]->Label,Type) == 0)
  35. return GlobalList[I];
  36. return 0;
  37. }
  38. /*}}}*/
  39. // IndexFile::ArchiveInfo - Stub /*{{{*/
  40. // ---------------------------------------------------------------------
  41. /* */
  42. string pkgIndexFile::ArchiveInfo(pkgCache::VerIterator Ver) const
  43. {
  44. return string();
  45. }
  46. /*}}}*/
  47. // IndexFile::FindInCache - Stub /*{{{*/
  48. // ---------------------------------------------------------------------
  49. /* */
  50. pkgCache::PkgFileIterator pkgIndexFile::FindInCache(pkgCache &Cache) const
  51. {
  52. return pkgCache::PkgFileIterator(Cache);
  53. }
  54. /*}}}*/
  55. // IndexFile::SourceIndex - Stub /*{{{*/
  56. // ---------------------------------------------------------------------
  57. /* */
  58. string pkgIndexFile::SourceInfo(pkgSrcRecords::Parser const &Record,
  59. pkgSrcRecords::File const &File) const
  60. {
  61. return string();
  62. }
  63. /*}}}*/
  64. // IndexFile::TranslationsAvailable - Check if will use Translation /*{{{*/
  65. // ---------------------------------------------------------------------
  66. /* */
  67. bool pkgIndexFile::TranslationsAvailable()
  68. {
  69. const string Translation = _config->Find("APT::Acquire::Translation");
  70. if (Translation.compare("none") != 0)
  71. return CheckLanguageCode(LanguageCode().c_str());
  72. else
  73. return false;
  74. }
  75. /*}}}*/
  76. // IndexFile::CheckLanguageCode - Check the Language Code /*{{{*/
  77. // ---------------------------------------------------------------------
  78. /* */
  79. /* common cases: de_DE, de_DE@euro, de_DE.UTF-8, de_DE.UTF-8@euro,
  80. de_DE.ISO8859-1, tig_ER
  81. more in /etc/gdm/locale.conf
  82. */
  83. bool pkgIndexFile::CheckLanguageCode(const char *Lang)
  84. {
  85. if (strlen(Lang) == 2 || (strlen(Lang) == 5 && Lang[2] == '_'))
  86. return true;
  87. if (strcmp(Lang,"C") != 0)
  88. _error->Warning("Wrong language code %s", Lang);
  89. return false;
  90. }
  91. /*}}}*/
  92. // IndexFile::LanguageCode - Return the Language Code /*{{{*/
  93. // ---------------------------------------------------------------------
  94. /* return the language code */
  95. string pkgIndexFile::LanguageCode()
  96. {
  97. const string Translation = _config->Find("APT::Acquire::Translation");
  98. if (Translation.compare("environment") == 0)
  99. {
  100. string lang = std::setlocale(LC_MESSAGES,NULL);
  101. // we have a mapping of the language codes that contains all the language
  102. // codes that need the country code as well
  103. // (like pt_BR, pt_PT, sv_SE, zh_*, en_*)
  104. char *need_full_langcode[] = { "pt","sv","zh","en", NULL };
  105. for(char **s = need_full_langcode;*s != NULL; s++)
  106. if(lang.find(*s) == 0)
  107. return lang.substr(0,5);
  108. if(lang.size() > 2)
  109. return lang.substr(0,2);
  110. else
  111. return lang;
  112. }
  113. else
  114. return Translation;
  115. }
  116. /*}}}*/