App_GlobalResources 資料夾,新增基礎資源檔 GlobalResource.resx。GlobalResource.en-US.resx(編碼遵循 RFC 1766)。TodayIs),分別設定值「今天是」與 "Today is"。<asp:Label Text="<%$ Resources:GlobalResource, TodayIs %>" />,或程式碼 Resources.GlobalResource.TodayIs。InitializeCulture(),設定 UICulture(影響資源檔選擇)與 Culture(影響日期/數字格式),最後呼叫 base.InitializeCulture()。也可在 `App_LocalResources,新增與頁面同名資源檔(如 Default.aspx.resx、Default.aspx.en-US.resx)。控件ID.屬性名(如 lblCurrentTime.Text)。<asp:Label runat="server" meta:resourcekey="lblCurrentTime" />,運行時自動依文化載入對應值。僅涉及日期/數字/字串格式轉換,取決於 Culture,與 UICulture 無關。
ScriptManager 設定 EnableScriptGlobalization="true"。localeFormat 方法格式化輸出,如 new Date().localeFormat("yyyy/MM/dd")。基於 JavaScript 檔案命名慣例:腳本名.文化編碼.js(如 DemoResource.js、DemoResource.en-US.js)。
Type.registerNamespace("Demo");
Demo.Resx = {
"TodayIs": "今天是"
};
ScriptManager 啟用並指定腳本路徑與支援文化:
<asp:ScriptManager ID="sm" runat="server" EnableScriptLocalization="true">
<Scripts>
<asp:ScriptReference Path="~/Scripts/DemoResource.js" ResourceUICultures="en-US" />
</Scripts>
</asp:ScriptManager>
document.write(Demo.Resx.TodayIs + new Date().localeFormat("yyyy/MM/dd"));,瀏覽器語言自動匹配對應 .js 檔。伺服器端依賴 .resx 資源檔與 Culture/UICulture;客戶端全球化靠 localeFormat,本地化靠多語系 .js 檔命名約定。兩者結合可構建完整的多語言 AJAX 應用。