{"id":804751,"date":"2024-07-29T00:16:45","date_gmt":"2024-07-28T16:16:45","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/804751.html"},"modified":"2024-07-29T00:16:48","modified_gmt":"2024-07-28T16:16:48","slug":"%e9%b8%bf%e8%92%99%e5%ba%94%e7%94%a8%e5%bc%80%e5%8f%91%e6%80%8e%e4%b9%88%e6%94%b9%e4%b8%ad%e6%96%87","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/804751.html","title":{"rendered":"\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u600e\u4e48\u6539\u4e2d\u6587"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25152316\/9471a087-dabd-456c-8627-8fcbd63d70d4.webp\" alt=\"\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u600e\u4e48\u6539\u4e2d\u6587\" \/><\/p>\n<p><p><strong>\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u6539\u4e2d\u6587\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\uff1a\u4fee\u6539\u5e94\u7528\u7684\u8bed\u8a00\u8d44\u6e90\u6587\u4ef6\u3001\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u8bed\u8a00\u3001\u786e\u4fdd\u591a\u8bed\u8a00\u517c\u5bb9\u3001\u5728\u5e94\u7528\u8bbe\u7f6e\u4e2d\u589e\u52a0\u8bed\u8a00\u9009\u9879\u3002<\/strong> \u4fee\u6539\u8bed\u8a00\u8d44\u6e90\u6587\u4ef6\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u901a\u8fc7\u5728\u9879\u76ee\u4e2d\u521b\u5efa\u5bf9\u5e94\u8bed\u8a00\u7684\u8d44\u6e90\u6587\u4ef6\u5939\uff0c\u5e76\u5c06\u7ffb\u8bd1\u540e\u7684\u6587\u672c\u653e\u5165\u5176\u4e2d\uff0c\u5e94\u7528\u5728\u8fd0\u884c\u65f6\u4f1a\u81ea\u52a8\u52a0\u8f7d\u76f8\u5e94\u7684\u8bed\u8a00\u8d44\u6e90\u3002\u4e0b\u9762\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4fee\u6539\u5e94\u7528\u7684\u8bed\u8a00\u8d44\u6e90\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5728\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u4e2d\uff0c\u8d44\u6e90\u6587\u4ef6\u901a\u5e38\u5b58\u50a8\u5728<code>resources<\/code>\u6587\u4ef6\u5939\u4e2d\uff0c\u6bcf\u4e2a\u8bed\u8a00\u7684\u8d44\u6e90\u6587\u4ef6\u5939\u4ee5\u8bed\u8a00\u4ee3\u7801\u547d\u540d\uff0c\u5982<code>values-zh<\/code>\uff08\u7b80\u4f53\u4e2d\u6587\uff09\u6216<code>values-zh-rTW<\/code>\uff08\u7e41\u4f53\u4e2d\u6587\uff09\u3002\u5728\u8fd9\u4e9b\u6587\u4ef6\u5939\u4e0b\uff0c\u53ef\u4ee5\u521b\u5efa\u5b57\u7b26\u4e32\u8d44\u6e90\u6587\u4ef6\uff08\u5982<code>strings.xml<\/code>\uff09\u6765\u5b9a\u4e49\u5e94\u7528\u4e2d\u7684\u6587\u672c\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u521b\u5efa\u8bed\u8a00\u8d44\u6e90\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u8d44\u6e90\u6587\u4ef6\u5939\uff0c\u4f8b\u5982<code>values-zh<\/code>\u3002\u7136\u540e\u5728\u8be5\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a<code>strings.xml<\/code>\u6587\u4ef6\u3002\u6587\u4ef6\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-xml\">&lt;resources&gt;<\/p>\n<p>    &lt;string name=&quot;app_name&quot;&gt;\u6211\u7684\u5e94\u7528&lt;\/string&gt;<\/p>\n<p>    &lt;string name=&quot;hello_world&quot;&gt;\u4f60\u597d\uff0c\u4e16\u754c\uff01&lt;\/string&gt;<\/p>\n<p>    &lt;!-- \u5176\u4ed6\u5b57\u7b26\u4e32\u8d44\u6e90 --&gt;<\/p>\n<p>&lt;\/resources&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1.2 \u4fee\u6539\u9ed8\u8ba4\u8bed\u8a00\u8d44\u6e90\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5728\u9ed8\u8ba4\u7684<code>values<\/code>\u6587\u4ef6\u5939\u4e2d\uff0c\u4e5f\u5e94\u8be5\u6709\u4e00\u4e2a<code>strings.xml<\/code>\u6587\u4ef6\u3002\u786e\u4fdd\u6240\u6709\u7684\u5b57\u7b26\u4e32\u90fd\u6709\u76f8\u5e94\u7684\u7ffb\u8bd1\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-xml\">&lt;resources&gt;<\/p>\n<p>    &lt;string name=&quot;app_name&quot;&gt;My Application&lt;\/string&gt;<\/p>\n<p>    &lt;string name=&quot;hello_world&quot;&gt;Hello, World!&lt;\/string&gt;<\/p>\n<p>    &lt;!-- \u5176\u4ed6\u5b57\u7b26\u4e32\u8d44\u6e90 --&gt;<\/p>\n<p>&lt;\/resources&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u5e94\u7528\u8fd0\u884c\u65f6\uff0c\u7cfb\u7edf\u4f1a\u6839\u636e\u8bbe\u5907\u7684\u8bed\u8a00\u8bbe\u7f6e\u81ea\u52a8\u9009\u62e9\u5408\u9002\u7684\u8d44\u6e90\u6587\u4ef6\u5939\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u8bed\u8a00<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u9700\u8981\u5728\u5e94\u7528\u4e2d\u52a8\u6001\u5207\u6362\u8bed\u8a00\uff0c\u8fd9\u65f6\u9700\u8981\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u8bed\u8a00\u3002\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u5e94\u7528\u7684<code>Configuration<\/code>\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u83b7\u53d6\u5f53\u524d\u8bed\u8a00<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u83b7\u53d6\u5f53\u524d\u8bbe\u5907\u7684\u8bed\u8a00\u8bbe\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Locale current = getResources().getConfiguration().locale;<\/p>\n<p>String currentLanguage = current.getLanguage();<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u52a8\u6001\u5207\u6362\u8bed\u8a00<\/h4>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u6765\u52a8\u6001\u5207\u6362\u8bed\u8a00\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">Locale locale = new Locale(&quot;zh&quot;);<\/p>\n<p>Locale.setDefault(locale);<\/p>\n<p>Configuration config = new Configuration();<\/p>\n<p>config.locale = locale;<\/p>\n<p>getResources().updateConfiguration(config, getResources().getDisplayMetrics());<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u5c06\u5e94\u7528\u7684\u8bed\u8a00\u8bbe\u7f6e\u4e3a\u7b80\u4f53\u4e2d\u6587\uff0c\u5e76\u66f4\u65b0\u914d\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u786e\u4fdd\u591a\u8bed\u8a00\u517c\u5bb9<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u786e\u4fdd\u5e94\u7528\u5728\u4e0d\u540c\u8bed\u8a00\u73af\u5883\u4e0b\u90fd\u80fd\u6b63\u5e38\u663e\u793a\u548c\u4f7f\u7528\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<p><h4>3.1 UI\u5e03\u5c40\u7684\u517c\u5bb9\u6027<\/h4>\n<\/p>\n<p><p>\u4e0d\u540c\u8bed\u8a00\u7684\u6587\u5b57\u957f\u5ea6\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\uff0c\u5c24\u5176\u662f\u4e2d\u6587\u4e0e\u82f1\u6587\u76f8\u6bd4\uff0c\u4e2d\u6587\u5b57\u7b26\u8f83\u5c11\u800c\u4fe1\u606f\u5bc6\u5ea6\u66f4\u9ad8\u3002\u56e0\u6b64\uff0c\u5728\u8bbe\u8ba1UI\u5e03\u5c40\u65f6\uff0c\u5e94\u786e\u4fdd\u6587\u672c\u6846\u3001\u6309\u94ae\u7b49\u63a7\u4ef6\u6709\u8db3\u591f\u7684\u7a7a\u95f4\u5bb9\u7eb3\u4e0d\u540c\u8bed\u8a00\u7684\u6587\u5b57\u3002<\/p>\n<\/p>\n<p><h4>3.2 \u5b57\u7b26\u7f16\u7801<\/h4>\n<\/p>\n<p><p>\u786e\u4fdd\u6240\u6709\u6587\u672c\u6587\u4ef6\u4f7f\u7528UTF-8\u7f16\u7801\uff0c\u4ee5\u652f\u6301\u591a\u8bed\u8a00\u5b57\u7b26\u96c6\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5728\u5e94\u7528\u8bbe\u7f6e\u4e2d\u589e\u52a0\u8bed\u8a00\u9009\u9879<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u5347\u7528\u6237\u4f53\u9a8c\uff0c\u53ef\u4ee5\u5728\u5e94\u7528\u7684\u8bbe\u7f6e\u4e2d\u589e\u52a0\u8bed\u8a00\u9009\u9879\uff0c\u5141\u8bb8\u7528\u6237\u624b\u52a8\u9009\u62e9\u5e94\u7528\u7684\u8bed\u8a00\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u521b\u5efa\u8bed\u8a00\u9009\u62e9\u754c\u9762<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u5728\u8bbe\u7f6e\u754c\u9762\u6dfb\u52a0\u4e00\u4e2a\u8bed\u8a00\u9009\u62e9\u9879\uff0c\u70b9\u51fb\u540e\u5f39\u51fa\u4e00\u4e2a\u5bf9\u8bdd\u6846\u8ba9\u7528\u6237\u9009\u62e9\u8bed\u8a00\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-xml\">&lt;string-array name=&quot;languages&quot;&gt;<\/p>\n<p>    &lt;item&gt;\u7b80\u4f53\u4e2d\u6587&lt;\/item&gt;<\/p>\n<p>    &lt;item&gt;English&lt;\/item&gt;<\/p>\n<p>&lt;\/string-array&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.2 \u5904\u7406\u7528\u6237\u9009\u62e9<\/h4>\n<\/p>\n<p><p>\u6839\u636e\u7528\u6237\u7684\u9009\u62e9\uff0c\u52a8\u6001\u4fee\u6539\u5e94\u7528\u7684\u8bed\u8a00\u8bbe\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-java\">public void changeLanguage(String languageCode) {<\/p>\n<p>    Locale locale = new Locale(languageCode);<\/p>\n<p>    Locale.setDefault(locale);<\/p>\n<p>    Configuration config = new Configuration();<\/p>\n<p>    config.locale = locale;<\/p>\n<p>    getResources().updateConfiguration(config, getResources().getDisplayMetrics());<\/p>\n<p>    \/\/ \u91cd\u542fActivity\u4ee5\u5e94\u7528\u65b0\u7684\u8bed\u8a00\u8bbe\u7f6e<\/p>\n<p>    recreate();<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5c06\u9e3f\u8499\u5e94\u7528\u4e2d\u7684\u8bed\u8a00\u6539\u4e3a\u4e2d\u6587\uff0c\u786e\u4fdd\u5e94\u7528\u5728\u4e0d\u540c\u8bed\u8a00\u73af\u5883\u4e0b\u7684\u517c\u5bb9\u6027\u548c\u826f\u597d\u7528\u6237\u4f53\u9a8c\u3002\u5177\u4f53\u7684\u5b9e\u73b0\u6b65\u9aa4\u5305\u62ec\u4fee\u6539\u8bed\u8a00\u8d44\u6e90\u6587\u4ef6\u3001\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u8bed\u8a00\u3001\u786e\u4fdd\u591a\u8bed\u8a00\u517c\u5bb9\u548c\u5728\u5e94\u7528\u8bbe\u7f6e\u4e2d\u589e\u52a0\u8bed\u8a00\u9009\u9879\u3002\u5e0c\u671b\u8fd9\u4e9b\u65b9\u6cd5\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u8fdb\u884c\u9e3f\u8499\u5e94\u7528\u7684\u591a\u8bed\u8a00\u5f00\u53d1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u4e2d\u5982\u4f55\u5207\u6362\u81f3\u4e2d\u6587\u754c\u9762\uff1f<\/strong><\/p>\n<ul>\n<li>\u5728\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u5de5\u5177\u4e2d\uff0c\u70b9\u51fb\u8bbe\u7f6e\uff08Settings\uff09\u9009\u9879\u3002<\/li>\n<li>\u5728\u8bbe\u7f6e\u754c\u9762\u4e2d\uff0c\u627e\u5230\u8bed\u8a00\uff08Language\uff09\u9009\u9879\u3002<\/li>\n<li>\u70b9\u51fb\u8bed\u8a00\u9009\u9879\uff0c\u5e76\u9009\u62e9\u4e2d\u6587\uff08Chinese\uff09\u4f5c\u4e3a\u754c\u9762\u8bed\u8a00\u5373\u53ef\u3002<\/li>\n<\/ul>\n<p><strong>2. \u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u4e2d\u5982\u4f55\u4f7f\u7528\u4e2d\u6587\u7f16\u5199\u4ee3\u7801\uff1f<\/strong><\/p>\n<ul>\n<li>\u5728\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u5de5\u5177\u4e2d\uff0c\u65b0\u5efa\u6216\u6253\u5f00\u4e00\u4e2a\u9879\u76ee\u3002<\/li>\n<li>\u5728\u4ee3\u7801\u7f16\u8f91\u5668\u4e2d\uff0c\u9009\u62e9\u4e2d\u6587\u8f93\u5165\u6cd5\uff0c\u7136\u540e\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u3002<\/li>\n<li>\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u5de5\u5177\u652f\u6301\u4e2d\u6587\u5b57\u7b26\u548c\u6c49\u5b57\u7684\u8f93\u5165\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u4e2d\u6587\u8fdb\u884c\u547d\u540d\u548c\u6ce8\u91ca\u3002<\/li>\n<\/ul>\n<p><strong>3. \u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u4e2d\u5982\u4f55\u8bbe\u7f6e\u4e2d\u6587\u5b57\u7b26\u7684\u663e\u793a\uff1f<\/strong><\/p>\n<ul>\n<li>\u5728\u5e03\u5c40\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u5de5\u5177\u63d0\u4f9b\u7684Text\u7ec4\u4ef6\u6765\u663e\u793a\u4e2d\u6587\u5b57\u7b26\u3002<\/li>\n<li>\u5728Text\u7ec4\u4ef6\u7684text\u5c5e\u6027\u4e2d\uff0c\u76f4\u63a5\u4f7f\u7528\u4e2d\u6587\u5b57\u7b26\u4f5c\u4e3a\u6587\u672c\u5185\u5bb9\u3002<\/li>\n<li>\u5982\u679c\u9047\u5230\u4e2d\u6587\u5b57\u7b26\u65e0\u6cd5\u6b63\u5e38\u663e\u793a\u7684\u60c5\u51b5\uff0c\u53ef\u4ee5\u68c0\u67e5\u5b57\u4f53\u8bbe\u7f6e\u548c\u5b57\u7b26\u7f16\u7801\uff0c\u786e\u4fdd\u652f\u6301\u4e2d\u6587\u5b57\u7b26\u7684\u663e\u793a\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u9e3f\u8499\u5e94\u7528\u5f00\u53d1\u6539\u4e2d\u6587\u7684\u65b9\u6cd5\u4e3b\u8981\u5305\u62ec\uff1a\u4fee\u6539\u5e94\u7528\u7684\u8bed\u8a00\u8d44\u6e90\u6587\u4ef6\u3001\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u8bed\u8a00\u3001\u786e\u4fdd\u591a\u8bed\u8a00\u517c\u5bb9\u3001\u5728\u5e94\u7528\u8bbe\u7f6e\u4e2d\u589e\u52a0\u8bed [&hellip;]","protected":false},"author":3,"featured_media":804761,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/804751"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=804751"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/804751\/revisions"}],"predecessor-version":[{"id":804763,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/804751\/revisions\/804763"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/804761"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=804751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=804751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=804751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}