1 // Copyright (c) 2010 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 declares a helper class for selecting a supported language from a
8 #ifndef CHROME_INSTALLER_UTIL_LANGUAGE_SELECTOR_H_
9 #define CHROME_INSTALLER_UTIL_LANGUAGE_SELECTOR_H_
14 #include "base/basictypes.h"
18 // A helper class for selecting a supported language from a set of candidates.
19 // By default, the candidates are retrieved from the operating system.
20 class LanguageSelector
{
22 // Default constructor will select from the set of languages supported by the
26 // Constructor for testing purposes.
27 explicit LanguageSelector(const std::vector
<std::wstring
>& candidates
);
31 // The offset of the matched language (i.e., IDS_L10N_OFFSET_*).
32 int offset() const { return offset_
; }
34 // The full name of the candidate language for which a match was found.
35 const std::wstring
& matched_candidate() const { return matched_candidate_
; }
37 // The name of the selected translation.
38 std::wstring
selected_translation() const { return GetLanguageName(offset_
); }
40 // Returns the name of a translation given its offset.
41 static std::wstring
GetLanguageName(int offset
);
44 typedef bool (*SelectPred_Fn
)(const std::wstring
&, int*);
46 static bool SelectIf(const std::vector
<std::wstring
>& candidates
,
47 SelectPred_Fn select_predicate
,
48 std::wstring
* matched_name
, int* matched_offset
);
49 void DoSelect(const std::vector
<std::wstring
>& candidates
);
51 std::wstring matched_candidate_
;
54 DISALLOW_COPY_AND_ASSIGN(LanguageSelector
);
57 } // namespace installer.
59 #endif // CHROME_INSTALLER_UTIL_LANGUAGE_SELECTOR_H_