2

【笨問題】防止 .NET 編譯產生不需要的多語系資源檔

 1 year ago
source link: https://blog.darkthread.net/blog/filter-res-lang-files/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

針對需要支援多語系的場合,.NET 標準做法是為各語系建立專屬資源檔,放入該語系的文字翻譯、專用圖示,Visual Studio 會將這些資源檔編譯成衛星組件(Satellite Assembly)。如此,執行時可依環境彈性載入,有專屬資源就用,沒有就用英文;開發時也可依需求逐步增加新語系,很方便。

但我一直有個困擾,當專案使用到支援多語系元件時,編譯資料夾就會生出一堆語系名稱資料夾,但我的網站沒有要服務歪果仁啊,冒出這麼多用不到的東西令人心煩。

Fig1_638017675225370182.png

之前遇到,我都很認命地手動刪檔,但想想不對,這太笨了,不像 .NET 的風格,應該有官方解法。

Yes! 在 .csproj 加上 SatelliteResourceLanguages,設定要包含的語系,這樣就行了! 可惡,我為什麼得過且過拖了這麼久?

Fig2_638017675229004953.png

and has 2 comments

Comments

Post a comment

Comment
Name Captcha 84 - 43 =

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK