• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "base/i18n/localization.h"
17 
18 namespace OHOS::Ace {
19 namespace {
20 constexpr int32_t DAY_COUNTS_OF_WEEK = 7;
21 constexpr int32_t MONTH_COUNTS_OF_YEAR = 12;
22 } // namespace
23 
24 struct LocaleProxy final {};
25 Localization::~Localization() = default;
26 
SetLocaleImpl(const std::string & language,const std::string & countryOrRegion,const std::string & script,const std::string & selectLanguage,const std::string & keywordsAndValues)27 void Localization::SetLocaleImpl(const std::string& language, const std::string& countryOrRegion,
28     const std::string& script, const std::string& selectLanguage, const std::string& keywordsAndValues)
29 {
30     languageTag_ = language;
31 }
32 
GetFontLocale()33 std::string Localization::GetFontLocale()
34 {
35     return fontLocale_;
36 }
37 
GetInstance()38 std::shared_ptr<Localization> Localization::GetInstance()
39 {
40     static auto instance = std::make_shared<Localization>();
41     return instance;
42 }
43 
GetDateOrder(std::vector<std::string> & outOrder)44 bool Localization::GetDateOrder(std::vector<std::string>& outOrder)
45 {
46     outOrder.clear();
47     if (languageTag_ == "ug") {
48         outOrder.emplace_back("month");
49         outOrder.emplace_back("day");
50         outOrder.emplace_back("year");
51     } else if (languageTag_ == "zh") {
52         outOrder.emplace_back("year");
53         outOrder.emplace_back("month");
54         outOrder.emplace_back("day");
55     } else if (languageTag_ == "false") {
56         return false;
57     }
58     return true;
59 }
60 
FormatDuration(uint32_t duration,const std::string & format)61 std::string Localization::FormatDuration(uint32_t duration, const std::string& format)
62 {
63     return "08:00:00";
64 }
65 
FormatDateTime(DateTime dateTime,const std::string & format)66 const std::string Localization::FormatDateTime(DateTime dateTime, const std::string& format)
67 {
68     return "08:00:00";
69 }
70 
FormatDateTime(DateTime dateTime,DateTimeStyle dateStyle,DateTimeStyle timeStyle)71 const std::string Localization::FormatDateTime(DateTime dateTime, DateTimeStyle dateStyle, DateTimeStyle timeStyle)
72 {
73     return "08:00:00";
74 }
75 
GetEntryLetters(const std::string & lettersIndex)76 std::string Localization::GetEntryLetters(const std::string& lettersIndex)
77 {
78     return "";
79 }
80 
GetErrorDescription(const std::string & errorIndex)81 std::string Localization::GetErrorDescription(const std::string& errorIndex)
82 {
83     return "";
84 }
85 
FormatDuration(uint32_t duration,bool needShowHour)86 const std::string Localization::FormatDuration(uint32_t duration, bool needShowHour)
87 {
88     return "08:00:00";
89 }
90 
GetMonths(bool isShortType,const std::string & calendarType)91 std::vector<std::string> Localization::GetMonths(bool isShortType, const std::string& calendarType)
92 {
93     std::vector<std::string> months;
94     for (int32_t i = 0; i < MONTH_COUNTS_OF_YEAR; i++) {
95         months.push_back(std::to_string(i));
96     }
97     return months;
98 }
99 
GetLanguage()100 std::string Localization::GetLanguage()
101 {
102     if (languageTag_.empty())
103         return "Chinese";
104     return languageTag_;
105 }
106 
GetLunarMonth(uint32_t month,bool isLeapMonth)107 std::string Localization::GetLunarMonth(uint32_t month, bool isLeapMonth)
108 {
109     return "";
110 }
111 
GetLunarDay(uint32_t dayOfMonth)112 std::string Localization::GetLunarDay(uint32_t dayOfMonth)
113 {
114     return "";
115 }
116 
GetLunarDate(Date date)117 LunarDate Localization::GetLunarDate(Date date)
118 {
119     LunarDate dateRet;
120     dateRet.year = date.year;
121     dateRet.month = date.month;
122     dateRet.day = date.day;
123     return dateRet;
124 }
125 
GetAmPmStrings()126 std::vector<std::string> Localization::GetAmPmStrings()
127 {
128     std::vector<std::string> amPms;
129     return amPms;
130 }
131 
GetHourFormat(bool & isAmPm,bool & hasZero)132 bool Localization::GetHourFormat(bool& isAmPm, bool& hasZero)
133 {
134     return false;
135 }
136 
137 // Mock get weekdays, 7 days in a week.
GetWeekdays(bool isShortType)138 std::vector<std::string> Localization::GetWeekdays(bool isShortType)
139 {
140     std::vector<std::string> weekdays;
141     for (int32_t i = 0; i < DAY_COUNTS_OF_WEEK; i++) {
142         weekdays.push_back(std::to_string(i));
143     }
144     return weekdays;
145 }
146 
NumberFormat(double number)147 std::string Localization::NumberFormat(double number)
148 {
149     return std::to_string(number);
150 }
151 } // namespace OHOS::Ace
152