Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / cld / encodings / lang_enc.h
blob0d2a4f19dd12914f466c42e0db544e963fb3b507
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This file is for i18n. It contains two enums, namely Language and
6 // Encoding, where Language is the linguistic convention, and Encoding
7 // contains information on both language encoding and character set.
8 //
9 // The language and encoding are both based on Teragram's conventions,
10 // except for some common ISO-8859 encodings that are not detected by
11 // Teragram but might be in the future.
13 // This file also includes functions that do mappings among
14 // Language/Encoding enums, language/encoding string names (typically
15 // the output from Language Encoding identifier), and language codes
16 // (iso 639), and two-letter country codes (iso 3166)
18 // NOTE: Both Language and Encoding enums should always start from
19 // zero value. This assumption has been made and used.
22 #ifndef ENCODINGS_LANG_ENC_H__
23 #define ENCODINGS_LANG_ENC_H__
25 #include "languages/public/languages.h"
26 #include "encodings/public/encodings.h"
29 // EncodingsForLanguage
30 // --------------------
32 // Given the language, returns a pointer to an array of encodings this
33 // language supports. Typically, the encs array has at least one
34 // element: UNKNOWN_ENCODING, which is always the last element of the
35 // array. The first encoding is the default encoding of the language.
36 // Return NULL if the input is invalid.
38 // Note: The output encoding array does not include ASCII_7BIT, UTF8
39 // or UNICODE which are good for all languages. TODO: Find out whether
40 // it is better to include ASCII_7BIT, UTF8 and UNICODE or leave them
41 // as special cases.
43 const Encoding* EncodingsForLanguage(Language lang);
46 // DefaultEncodingForLanguage
47 // --------------------------
49 // Given the language, returns the default encoding for the language
50 // via the argument encoding.
52 // The function returns true if the input lang is valid. Otherwise,
53 // false is returned, and encoding is set to UNKNOWN_ENCODING.
55 bool DefaultEncodingForLanguage(Language lang,
56 Encoding *encoding);
58 // LanguagesForEncoding
59 // --------------------
61 // Given the encoding, returns a pointer to an array of languages this
62 // encoding supports. Typically, the langs array has at least one
63 // element: UNKNOWN_LANGUAGE, which is always the last element of the
64 // array. The first language in the array if the most popular
65 // language for that encoding. NULL is returned if the input is
66 // invalid.
68 // Note: For ASCII_7BIT, UNICODE and UTF8, only ENGLISH and
69 // UNKNOWN_LANGUAGE are returned. TODO: Find out whether to return all
70 // the languages or to treat these two encodings as special cases.
72 // For other known encodings, ENGLISH is always included. This is
73 // because English (Latin) characters are included in each encoding.
75 const Language* LanguagesForEncoding(Encoding enc);
77 // DefaultLanguageForEncoding
78 // --------------------------
80 // Given the encoding, returns the default language for that encoding
81 // via the argument language.
83 // The function returns true if the input enc is valid. Otherwise,
84 // false is returned, and language is set to UNKNOWN_LANGUAGE.
86 // Note, this function is more useful for the encodings that have only
87 // one corresponding language i.e. shift_jis => Japanese. There are
88 // cases that multiple langauges have the same encoding, for which the
89 // default language is an arbitrary choice from them.
91 bool DefaultLanguageForEncoding(Encoding enc, Language* language);
94 // IsLangEncCompatible
95 // -------------------
97 // This function is to determine whether the input language and
98 // encoding are compatible. For example, FRENCH and LATIN1 are
99 // compatible, but FRENCH and GB are not.
101 // If either lang or enc is invalid return false.
102 // If either lang is unknown, return true.
103 // (e.g. we can detect a page's encoding as latin1 from metatag info, but
104 // cannot derive it language since there are more than one
105 // language encoding in Latin1 )
106 // If language is known, but encoding is unknown, return false.
107 // (return true will do us no good since we cannot convert to UTF8 anyway)
108 // If enc is unicode or utf8, return true.
109 // Otherwise check if lang is supported by enc and enc supported by
110 // lang.
112 bool IsLangEncCompatible(Language lang, Encoding enc);
115 // DominantLanguageFromEncoding
116 // ----------------------------
118 // This function determine if there exists a dominant language for the
119 // input encoding. For example, the encoding GB has a dominant
120 // language (Chinese), but Latin1 does not.
122 // The word "dominant" is used here because English characters are
123 // included in each encoding.
125 // If there is no dominant langauge for the encoding, such as Latin1,
126 // UNKNOWN_LANGUAGE is returned.
128 Language DominantLanguageFromEncoding(Encoding enc);
130 // LanguageCode
131 // ------------------------
132 // Given the Language and Encoding, return language code with dialects
133 // (>= 2 letters). Encoding is necessary to disambiguate between
134 // Simplified and Traditional Chinese.
136 // See the note on Chinese Language Codes in
137 // i18n/languages/public/languages.h
138 // for the details.
140 const char* LanguageCode(Language lang, Encoding enc);
143 // IsEncodingWithSupportedLanguage()
144 // ---------------------------------
146 // There are some encoding listed here just because they are commonly
147 // used. There is no interface language for them yet. They are not
148 // detected by Teragram, but can be detected from the meta info of the
149 // HTML page.
151 // For example, we have list ARABIC_ENCODING but there is no arabic in
152 // the Language enum. If the user input an Arabic query from Google
153 // main page, Netscape will just send the raw bytes to GWS, and GWS
154 // will treat them as Latin1. Therefore, there is no use to detect
155 // ARABIC_ENCODING for indexing, since they will never match the
156 // queries which are treated as Latin1 by GWS. On the contrary, if we
157 // treat page with ARABIC_ENCODING as UNKNOWN_ENCODING, Google will
158 // fall them through as Latin1 in indexing time. And there might be a
159 // match for some ARABIC queries which are also treated as Latin1 by
160 // GWS. In fact, some people are relying on this feature to do Arabic
161 // searches.
163 // Thus for these type of encoding, before we have the UI support for
164 // their language and have a pretty comprehensive language/encoding
165 // identification quality, it is better to revert them as
166 // UNKNOWN_ENCODING.
168 // This function checks whether the input encoding is one with
169 // an interface language.
170 bool IsEncodingWithSupportedLanguage(Encoding enc);
174 // LangsFromCountryCode and EncFromCountryCode
175 // -------------------------------------------
177 // These two functions return the possible languages and encodings,
178 // respectively, according to the input country code, which is a
179 // 2-letter string. The country code is usually specified in the url
180 // of a document.
184 // LangsFromCountryCode
185 // --------------------
187 // This function takes a string of arbitrary length. It treats the
188 // first 2 bytes of the string as the country code, as defined in iso
189 // 3166-1993 (E). It returns, via arguments, an array of the
190 // languages that are popular in that country, roughly in order of
191 // popularity, together with the size of the array.
193 // This function returns true if we have language information for
194 // country_code. Otherwise, it returns false.
196 bool LangsFromCountryCode(const char* country_code,
197 const Language** lang_arry,
198 int* num_langs);
202 // EncFromCountryCode
203 // ------------------
205 // This function takes a string of arbitrary length. It treats the
206 // first 2 bytes of that string as the country code, as defined in iso
207 // 3166-1993 (E). It sets *enc to the encoding that is
208 // most often used for the languages spoken in that country.
210 // This function returns true if we have encoding information for
211 // country_code. Otherwise, it returns false, and *enc is set to
212 // UNKNOWN_ENCODING.
214 bool EncFromCountryCode(const char* country_code, Encoding* enc);
218 // VisualType
219 // ----------
221 // Right-to-left documents may be in logical or visual order. When they
222 // are in visual order we convert them to logical order before processing.
223 // This enum lists the types of visual document we can encounter.
224 // Some, but not all, documents in Hebrew/Arabic/Persian etc. will be visual.
225 // The other documents in those languages, and all documents in non-RTL
226 // languages, will be NOT_VISUAL_DOCUMENT.
227 enum VisualType {
228 NOT_VISUAL_DOCUMENT = 0,
229 VISUAL_HEBREW_HTML, // HTML documents in the legacy visual order.
230 CONVERTED_RTL_PDF, // Converted RTL PDFs, which are always visual.
233 VisualType default_visualtype();
235 // VisualTypeName
236 // --------------
238 // Given the visual type, returns a string name useful for debug output.
239 const char* VisualTypeName(VisualType visualtype);
243 // InitLangEnc
244 // -----------
246 // Ensures the LangEnc module has been initialized. Normally this
247 // happens during InitGoogle, but this allows access for scripts that
248 // don't support InitGoogle. InitLangEnc calls InitEncodings (see
249 // i18n/encodings/public/encodings.h) and also initializes data
250 // structures used in lang_enc.cc.
252 void InitLangEnc();
254 #endif // ENCODINGS_LANG_ENC_H__