1bea4f105Sopenharmony_ci/*
2bea4f105Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3bea4f105Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bea4f105Sopenharmony_ci * you may not use this file except in compliance with the License.
5bea4f105Sopenharmony_ci * You may obtain a copy of the License at
6bea4f105Sopenharmony_ci *
7bea4f105Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bea4f105Sopenharmony_ci *
9bea4f105Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bea4f105Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bea4f105Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bea4f105Sopenharmony_ci * See the License for the specific language governing permissions and
13bea4f105Sopenharmony_ci * limitations under the License.
14bea4f105Sopenharmony_ci */
15bea4f105Sopenharmony_ci
16bea4f105Sopenharmony_ciimport i18n from '@ohos.i18n'
17bea4f105Sopenharmony_ci
18bea4f105Sopenharmony_cinamespace LanguageUtil {
19bea4f105Sopenharmony_ci/**
20bea4f105Sopenharmony_ci * @description 获取系统语言
21bea4f105Sopenharmony_ci * @return string 系统语言ID,如zh-Hans
22bea4f105Sopenharmony_ci */
23bea4f105Sopenharmony_ci    export const getSystemLanguage = (): string => {
24bea4f105Sopenharmony_ci        return i18n.getSystemLanguage()
25bea4f105Sopenharmony_ci    }
26bea4f105Sopenharmony_ci
27bea4f105Sopenharmony_ci    /**
28bea4f105Sopenharmony_ci     * @description 获取系统地区
29bea4f105Sopenharmony_ci     * @return string 系统地区ID,如:CN
30bea4f105Sopenharmony_ci     */
31bea4f105Sopenharmony_ci    export const getSystemRegion = (): string => {
32bea4f105Sopenharmony_ci        return i18n.getSystemRegion()
33bea4f105Sopenharmony_ci    }
34bea4f105Sopenharmony_ci
35bea4f105Sopenharmony_ci    /**
36bea4f105Sopenharmony_ci     * 判断是否是中文语言
37bea4f105Sopenharmony_ci     * @return boolean
38bea4f105Sopenharmony_ci     */
39bea4f105Sopenharmony_ci    export function isChineseLanguage(): boolean {
40bea4f105Sopenharmony_ci        const language = getSystemLanguage().split('-')[0]
41bea4f105Sopenharmony_ci        return language === 'zh'
42bea4f105Sopenharmony_ci    }
43bea4f105Sopenharmony_ci
44bea4f105Sopenharmony_ci    /**
45bea4f105Sopenharmony_ci     * 判断是否是中文语言,包括中文、藏文、维语
46bea4f105Sopenharmony_ci     * @return boolean
47bea4f105Sopenharmony_ci     */
48bea4f105Sopenharmony_ci    export function isChineseGroupLanguage(): boolean {
49bea4f105Sopenharmony_ci        const language = getSystemLanguage().split('-')[0]
50bea4f105Sopenharmony_ci        return language === 'zh' || language === 'bo' || language === 'ug'
51bea4f105Sopenharmony_ci    }
52bea4f105Sopenharmony_ci
53bea4f105Sopenharmony_ci    /**
54bea4f105Sopenharmony_ci     * 判断是否是英文语言
55bea4f105Sopenharmony_ci     * @return boolean
56bea4f105Sopenharmony_ci     */
57bea4f105Sopenharmony_ci    export function isEnglishLanguage(): boolean {
58bea4f105Sopenharmony_ci        const language = getSystemLanguage().split('-')[0]
59bea4f105Sopenharmony_ci        return language === 'en'
60bea4f105Sopenharmony_ci    }
61bea4f105Sopenharmony_ci}
62bea4f105Sopenharmony_ci
63bea4f105Sopenharmony_ciexport default LanguageUtil