Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <svtools/svtresid.hxx>
22 : #include <svtools/svtools.hrc>
23 : #include <svtools/collatorres.hxx>
24 :
25 : // -------------------------------------------------------------------------
26 : //
27 : // wrapper for locale specific translations data of collator algorithm
28 : //
29 : // -------------------------------------------------------------------------
30 :
31 : class CollatorResourceData
32 : {
33 : friend class CollatorResource;
34 : private: /* data */
35 : rtl::OUString ma_Name;
36 : rtl::OUString ma_Translation;
37 : private: /* member functions */
38 0 : CollatorResourceData () {}
39 : public:
40 0 : CollatorResourceData ( const rtl::OUString &r_Algorithm, const rtl::OUString &r_Translation)
41 0 : : ma_Name (r_Algorithm), ma_Translation (r_Translation) {}
42 :
43 0 : const rtl::OUString& GetAlgorithm () const { return ma_Name; }
44 :
45 0 : const rtl::OUString& GetTranslation () const { return ma_Translation; }
46 :
47 0 : ~CollatorResourceData () {}
48 :
49 0 : CollatorResourceData& operator= (const CollatorResourceData& r_From)
50 : {
51 0 : ma_Name = r_From.GetAlgorithm();
52 0 : ma_Translation = r_From.GetTranslation();
53 0 : return *this;
54 : }
55 : };
56 :
57 : // -------------------------------------------------------------------------
58 : //
59 : // implementation of the collator-algorithm-name translation
60 : //
61 : // -------------------------------------------------------------------------
62 :
63 : #define COLLATOR_RESOURCE_COUNT (STR_SVT_COLLATE_END - STR_SVT_COLLATE_START + 1)
64 :
65 0 : CollatorResource::CollatorResource()
66 : {
67 0 : mp_Data = new CollatorResourceData[COLLATOR_RESOURCE_COUNT];
68 :
69 : #define ASCSTR(str) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(str))
70 : #define RESSTR(rid) SvtResId(rid).toString()
71 :
72 0 : mp_Data[0] = CollatorResourceData (ASCSTR("alphanumeric"), RESSTR(STR_SVT_COLLATE_ALPHANUMERIC));
73 0 : mp_Data[1] = CollatorResourceData (ASCSTR("charset"), RESSTR(STR_SVT_COLLATE_CHARSET));
74 0 : mp_Data[2] = CollatorResourceData (ASCSTR("dict"), RESSTR(STR_SVT_COLLATE_DICTIONARY));
75 0 : mp_Data[3] = CollatorResourceData (ASCSTR("normal"), RESSTR(STR_SVT_COLLATE_NORMAL));
76 0 : mp_Data[4] = CollatorResourceData (ASCSTR("pinyin"), RESSTR(STR_SVT_COLLATE_PINYIN));
77 0 : mp_Data[5] = CollatorResourceData (ASCSTR("radical"), RESSTR(STR_SVT_COLLATE_RADICAL));
78 0 : mp_Data[6] = CollatorResourceData (ASCSTR("stroke"), RESSTR(STR_SVT_COLLATE_STROKE));
79 0 : mp_Data[7] = CollatorResourceData (ASCSTR("unicode"), RESSTR(STR_SVT_COLLATE_UNICODE));
80 0 : mp_Data[8] = CollatorResourceData (ASCSTR("zhuyin"), RESSTR(STR_SVT_COLLATE_ZHUYIN));
81 0 : mp_Data[9] = CollatorResourceData (ASCSTR("phonebook"), RESSTR(STR_SVT_COLLATE_PHONEBOOK));
82 0 : mp_Data[10] = CollatorResourceData (ASCSTR("phonetic (alphanumeric first)"), RESSTR(STR_SVT_COLLATE_PHONETIC_F));
83 0 : mp_Data[11] = CollatorResourceData (ASCSTR("phonetic (alphanumeric last)"), RESSTR(STR_SVT_COLLATE_PHONETIC_L));
84 0 : }
85 :
86 0 : CollatorResource::~CollatorResource()
87 : {
88 0 : delete[] mp_Data;
89 0 : }
90 :
91 : const rtl::OUString&
92 0 : CollatorResource::GetTranslation(const rtl::OUString &r_Algorithm)
93 : {
94 0 : sal_Int32 nIndex = r_Algorithm.indexOf('.');
95 0 : rtl::OUString aLocaleFreeAlgorithm;
96 :
97 0 : if (nIndex == -1)
98 : {
99 0 : aLocaleFreeAlgorithm = r_Algorithm;
100 : }
101 : else
102 : {
103 0 : nIndex += 1;
104 0 : aLocaleFreeAlgorithm = r_Algorithm.copy(nIndex, r_Algorithm.getLength() - nIndex);
105 : }
106 :
107 0 : for (sal_uInt32 i = 0; i < COLLATOR_RESOURCE_COUNT; i++)
108 : {
109 0 : if (aLocaleFreeAlgorithm == mp_Data[i].GetAlgorithm())
110 0 : return mp_Data[i].GetTranslation();
111 : }
112 :
113 0 : return r_Algorithm;
114 : }
115 :
116 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|