android 系统如何添加多语言支持

版权声明:转载请注明出处。谢谢 https://blog.csdn.net/xct841990555/article/details/81660493

之前在项目中遇到了这样一个问题,因为项目要适配多语言,但是奇怪的是,在android 的自带的setting=》language列表中和开机导航页中有好几种语言就是显示不出来。

解决:

framework/base/core/res/res/下添加如下:

增加对应语言的的文件夹(eg:中国台湾),并且该文件夹中有以下两个文件(目录结构如下):在这里插入图片描述

其中,第一个文件:donottranslate-maps.xml 内容如下(这个文件好像也可以不要):

<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/colors.xml
**
** Copyright 2006, Google Inc.
**
** Licensed under the Apache License, Version 2.0 (the "License"); 
** you may not use this file except in compliance with the License. 
** You may obtain a copy of the License at 
**
**     http://www.apache.org/licenses/LICENSE-2.0 
**
** Unless required by applicable law or agreed to in writing, software 
** distributed under the License is distributed on an "AS IS" BASIS, 
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
** See the License for the specific language governing permissions and 
** limitations under the License.
*/
-->
<resources>

    <!-- Do not translate. -->
    <integer-array name="maps_starting_lat_lng">
        <item>40083518</item>(这两个是对应国家的经纬度)
        <item>4734369</item>
    </integer-array>
    <!-- Do not translate. -->
    <integer-array name="maps_starting_zoom">
        <item>4</item>
    </integer-array>

</resources>

strings.xml
此文件下为android系统中主要的翻译,具体可以根据英语文件夹下的翻译。一版低版本上都有。可以直接拷过来

另外这还不算完,前面只是配置了android系统支持此语言,但是要是想要在开机导航和settings中显示对应的国家语言,还要在以下文件中配置。
在device下的oem.mk文件中(名字不一定为oem.mk,一版为厂商名字或者特定的名字.mk

# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

export MODEL_NAME=globe_na
# Follow the same default value which defined in sys-build.
ifndef ARCHER_BOARD
export ARCHER_BOARD := false
endif

# To prevent from including GMS twice in Google's internal source.
ifeq ($(wildcard vendor/google/prebuilt),)
PRODUCT_USE_PREBUILT_GMS := yes
endif

PRODUCT_PROPERTY_OVERRIDES := \
        net.dns1=8.8.8.8 \
        net.dns2=8.8.4.4

PRODUCT_PROPERTY_OVERRIDES += \
        ro.mtk.system.marketregion=us \
        ro.mtk.system.audiosync=1 \
        ro.mtk.system.av_record_lib=1 \
        ro.mtk.system.cec.hal=1 \
        ro.mtk.twoworlds=1 \
        ro.mtk.sys_driver_only=0 \
        ro.mtk.system.timesync.existed=1 \
        ro.config.ts.date.time=false
		
# Patch for skyworth +hanq >>>
PRODUCT_PROPERTY_OVERRIDES += \
    ro.product.swid=000S000 \
    ro.build.overseas.version=003
# Patch for skyworth +hanq <<<

# Inherit from those products. Most specific first.
$(call inherit-product-if-exists, device/toshiba/globe/kane_build_apollo.mk)
$(call inherit-product, device/toshiba/globe/device.mk)
$(call inherit-product, device/google/atv/products/atv_base.mk)

PRODUCT_BOOT_JARS += com.mediatek.mtkaudiopatchmanager 

PRODUCT_NAME := globe_na
PRODUCT_BRAND := globe_ATV
PRODUCT_DEVICE := globe_na
PRODUCT_MODEL := globe
#sky wayhome modify for PRODUCT_MANUFACTURER netflix test, 2018.01.25
PRODUCT_MANUFACTURER := Skyworth
export TV_WORK_WITH_ALEXA_SUPPORT ?=true
# Put en_US first in the list, so make it default.
PRODUCT_LOCALES := en_US en_CA fr_CA es_ES ko_KR zh_CN zh_TW(***在此行配置对应的语言缩写***)
# inherit from the non-open-source part, if present
$(call inherit-product-if-exists, vendor/toshiba_globe/device-vendor.mk)

# Build WebView from source when using the internal source.
override PRODUCT_PREBUILT_WEBVIEWCHROMIUM := $(PRODUCT_USE_PREBUILT_GMS)

这样,就可以显示想要的国家语言了。

猜你喜欢

转载自blog.csdn.net/xct841990555/article/details/81660493