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