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