<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 豆腐結 on Medium]]></title>
        <description><![CDATA[Stories by 豆腐結 on Medium]]></description>
        <link>https://medium.com/@tofujie?source=rss-1d6851644e4d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*u6tAa_gl3EOGMBFAQPhb2g.jpeg</url>
            <title>Stories by 豆腐結 on Medium</title>
            <link>https://medium.com/@tofujie?source=rss-1d6851644e4d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:49:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tofujie/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[iOS 多國語(Localization)實作的意外問題(坑)]]></title>
            <link>https://medium.com/@tofujie/ios-%E5%A4%9A%E5%9C%8B%E8%AA%9E-localization-%E5%AF%A6%E4%BD%9C%E7%9A%84%E6%84%8F%E5%A4%96%E5%95%8F%E9%A1%8C-%E5%9D%91-738332b0493c?source=rss-1d6851644e4d------2</link>
            <guid isPermaLink="false">https://medium.com/p/738332b0493c</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[localization]]></category>
            <dc:creator><![CDATA[豆腐結]]></dc:creator>
            <pubDate>Mon, 14 Oct 2024 06:04:53 GMT</pubDate>
            <atom:updated>2024-10-14T08:06:37.339Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t6ifUGvkizMoHsTg" /><figcaption>Photo by <a href="https://unsplash.com/@lingapp?utm_source=medium&amp;utm_medium=referral">Ling App</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>iOS 多國語如何設定，網路上已經有許多詳細的手把手教學，因近年 iOS 就這部分的更動不大，故不再贅述。可以參考：</p><ul><li><a href="https://franksios.medium.com/ios-localization-%E6%9C%AC%E5%9C%B0%E5%8C%96-7b16b58bb9df">iOS 關於多國語系的那些事(Localization)</a></li><li><a href="https://medium.com/zrealm-ios-dev/ios-%E7%82%BA%E5%A4%9A%E8%AA%9E%E7%B3%BB%E5%AD%97%E4%B8%B2%E8%B2%B7%E4%BB%BD%E4%BF%9D%E9%9A%AA%E5%90%A7-48a8526c1300">iOS 為多語系字串買份保險吧！</a></li></ul><p>這篇文章主要想分享在實作上，遇到的意外問題，也就是坑(?)，以及可能的解法供參考。</p><p>本篇文章的多國語設定是使用 Strings File，也就是 Localizable.strings 檔案，並非 Xcode 15 後支援 SwiftUI 的 String Catalog。</p><p>(如專案是純 SwiftUI 開發，String Catalog 很好用，但如果有使用 UIKit 或混合開發，則現階段還是推薦使用 Localizable.strings。)</p><h4>不同語系的翻譯順序差異</h4><p>在不同語系中，文字順序往往不同，因此需要針對每個語系進行特殊處理。</p><p>直接看範例：<br>繁體中文文案為「今日已獲得 1 個星星」，因「1 個」和「星星」需為不同字型和顏色，故拆分為三個 key 值：</p><pre>&quot;today_gained&quot; = &quot;今日已獲得&quot;;<br>&quot;one_unit&quot; = &quot;1 個&quot;;<br>&quot;star&quot; = &quot;星星&quot;;</pre><p>然而在英文，對應的文案為「Obtained 1 Today」，不僅語意不同，順序也與中文不同，因此無法沿用相同的 key 值配置。我們需要在英文的 Localizable.strings 中新增相對應的 key 值，但對於不需要的內容可以設為空字串，再新增專門給英文的 key：：</p><pre>&quot;today_gained&quot; = &quot;Obtained&quot;;<br>&quot;one_unit&quot; = &quot;1&quot;;<br>&quot;star&quot; = &quot;&quot;;<br>&quot;today&quot; = &quot;Today&quot;</pre><p><strong><em>**優化解法：統一 key 命名格式**</em></strong></p><p>上述方式在程式碼中容易造成混亂，也可能導致顯示順序出錯。因此，建議將 key 值重新整理為一致的命名格式，如下：</p><pre>// 繁體中文<br>&quot;today_gained_title_1&quot; = &quot;今日已獲得&quot;;<br>&quot;today_gained_title_2&quot; = &quot;1 個&quot;;<br>&quot;today_gained_title_3&quot; = &quot;星星&quot;;<br>&quot;today_gained_title_4&quot; = &quot;&quot;<br><br>// 英文<br>&quot;today_gained_title_1&quot; = &quot;Obtained&quot;;<br>&quot;today_gained_title_2&quot; = &quot;1&quot;;<br>&quot;today_gained_title_3&quot; = &quot;&quot;;<br>&quot;today_gained_title_4&quot; = &quot;Today&quot;</pre><p>在程式碼中，按照 title_1 <strong>到</strong> title_4 的順序顯示所有 key 值即可，無論語系為何，都能保持正確的顯示順序與格式。</p><h4><strong>LaunchScreen 無法設定多國語</strong></h4><p>在 LaunchScreen 中使用多國語言時，系統僅顯示英文，無法根據使用者的語系設定正確顯示對應的語言。根據 <a href="https://developer.apple.com/design/human-interface-guidelines/launching">Apple Human Interface Guideline</a>，Apple 建議避免在 LaunchScreen 中使用文字：</p><blockquote><em>“Avoid including text on your launch screen, even if your first screen displays text. Because the content in a launch screen doesn’t change, any text you display won’t be localized.”</em></blockquote><p>因此，建議在 LaunchScreen 中避免使用任何文字，包含圖片上的文字，以確保使用者體驗一致。</p><h4>iOS 17 抓取近似語言的問題</h4><p>在 iOS 17 中遇到一個多國語對應的問題：系統會將繁體中文的圖片顯示為簡體中文的圖片，但英文顯示正常。根據<a href="https://developer.apple.com/help/app-store-connect/manage-app-information/localize-app-information/">官方文件</a>：</p><blockquote><em>“If there’s no localization available that matches the language setting, the next most relevant localization is used.”</em></blockquote><p>這代表當系統無法找到對應語言的資源時，會自動使用最接近的語言資源。然而，在 iOS 15 和 iOS 16 上並未出現此問題，因此推測這可能是 iOS 17 的系統問題，導致無法正確抓到繁體中文的圖片。</p><p><strong><em>**暫時解法：避免使用 Xcode Asset 的內建多國語功能，透過圖片檔案名稱管理來手動實現多國語言支援**</em></strong></p><ol><li>假設圖片名稱為 setting：</li></ol><ul><li>英文版圖片命名為 settingEn</li><li>簡體中文版圖片命名為 settingZhs，以此類推</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*UTg77zNxGb9yTaXAQLsTvQ.jpeg" /><figcaption>圖片檔案命名方式</figcaption></figure><p>2. 在 Localizable.strings 中，新增一個專門給圖片用的 key，例如：</p><pre>// 英文<br>&quot;imageLocal&quot; = &quot;En&quot;;<br><br>// 簡體中文<br>&quot;imageLocal&quot; = &quot;Zhs&quot;;</pre><p>3. 使用圖片時，根據語系組合檔名：</p><pre>let imageName = &quot;setting&quot; + NSLocalizedString(&quot;imageLocal&quot;, comment: &quot;&quot;)</pre><p>這樣的作法可以確保不同語系的圖片能正確被系統抓取顯示。不需要多國語的圖片則保持原樣，不進行任何命名變更。</p><p>以上為實作 iOS 多國語遇到的意外問題及解法，若有錯誤或是其他建議，請不吝留言給我，謝謝你的觀看。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=738332b0493c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>