]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/frnt_lang.C
5 new lfuns, move all apply code out of ControlDocument and into the core.
[lyx.git] / src / frontends / controllers / frnt_lang.C
1 /**
2  * \file frnt_lang.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13
14 #include "frnt_lang.h"
15 #include "gettext.h"
16 #include "language.h"
17
18 #include <algorithm>
19
20
21 using std::string;
22 using std::vector;
23
24
25 namespace {
26
27 struct Sorter
28         : public std::binary_function<frnt::LanguagePair,
29                                       frnt::LanguagePair, bool>
30 {
31         bool operator()(frnt::LanguagePair const & lhs,
32                         frnt::LanguagePair const & rhs) const {
33                 return lhs.first < rhs.first;
34         }
35 };
36
37 } // namespace anon
38
39 namespace frnt {
40
41 vector<LanguagePair> const getLanguageData(bool character_dlg)
42 {
43         vector<LanguagePair>::size_type const size = character_dlg ?
44                 languages.size() + 2 : languages.size();
45
46         vector<LanguagePair> langs(size);
47
48         if (character_dlg) {
49                 langs[0].first = _("No change");
50                 langs[0].second = "ignore";
51                 langs[1].first = _("Reset");
52                 langs[1].second = "reset";
53         }
54
55         vector<string>::size_type i = character_dlg ? 2 : 0;
56         for (Languages::const_iterator cit = languages.begin();
57              cit != languages.end(); ++cit) {
58                 langs[i].first  = _(cit->second.display());
59                 langs[i].second = cit->second.lang();
60                 ++i;
61         }
62
63         // Don't sort "ignore" and "reset"
64         vector<LanguagePair>::iterator begin = character_dlg ?
65                 langs.begin() + 2 : langs.begin();
66
67         std::sort(begin, langs.end(), Sorter());
68
69         return langs;
70 }
71
72 } // namespace frnt