indexfile.cc 3.9 KB

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