新聞中心
部署多個語言環(huán)境
如果 ?myapp ?是包含項目可分發(fā)文件的目錄,你通常會在語言環(huán)境目錄中為不同的語言環(huán)境提供不同的版本,比如法語版的 ?myapp/fr? 和西班牙語版的 ?myapp/es?。

創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設,銅陵企業(yè)網(wǎng)站建設,銅陵品牌網(wǎng)站建設,網(wǎng)站定制,銅陵網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,銅陵網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
帶有 ?href? 屬性的 HTML ?base ?標簽指定了相對鏈接的基本 URI 或 URL。如果你將工作空間構建配置文件 ?Angular.json? 中的 ?"localize"? 選項設置為 ?true ?或語言環(huán)境 ID 數(shù)組,CLI 會為應用程序的每個版本調整 base ?href?。要為應用程序的每個版本調整 base ?href?,CLI 會將語言環(huán)境添加到配置的 ?"baseHref"? 中。在工作區(qū)配置文件 ?angular.json? 中為每個語言環(huán)境指定 ?"baseHref"?。以下示例展示了設置為空字符串的 ?"baseHref"?。
"projects": {
"angular.io-example": {
// ...
"i18n": {
"sourceLocale": "en-US",
"locales": {
"fr": {
"translation": "src/locale/messages.fr.xlf",
"baseHref": ""
}
}
},
"architect": {
// ...
}
}
}
// ...
}此外,要在編譯時聲明 base ?href?,請將在 CLI 中使用帶有 ?--baseHref? 選項的 ?ng build? 。
配置服務器
多語言的典型部署方式是為來自不同子目錄的每種語言提供服務。使用 ?Accept-Language? HTTP 標頭將用戶重定向到瀏覽器中定義的首選語言。如果用戶未定義首選語言,或者首選語言不可用,則服務器將回退到默認語言。要更改語言,就轉到另一個子目錄。 子目錄的更改通常使用應用程序中實現(xiàn)的菜單進行。
Nginx 范例
以下示例展示了 Nginx 配置。
http {
# Browser preferred language detection (does NOT require
# AcceptLanguageModule)
map $http_accept_language $accept_language {
~*^de de;
~*^fr fr;
~*^en en;
}
# ...
}
server {
listen 80;
server_name localhost;
root /www/data;
# Fallback to default language if no preference defined by browser
if ($accept_language ~ "^$") {
set $accept_language "fr";
}
# Redirect "/" to Angular application in the preferred language of the browser
rewrite ^/$ /$accept_language permanent;
# Everything under the Angular application is always redirected to Angular in the
# correct language
location ~ ^/(fr|de|en) {
try_files $uri /$1/index.html?$args;
}
# ...
}Apache 范例
以下示例展示了 Apache 配置。
ServerName localhost
DocumentRoot /www/data
RewriteEngine on
RewriteBase /
RewriteRule ^../index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (..) $1/index.html [L]
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ /de/ [R]
RewriteCond %{HTTP:Accept-Language} ^en [NC]
RewriteRule ^$ /en/ [R]
RewriteCond %{HTTP:Accept-Language} !^en [NC]
RewriteCond %{HTTP:Accept-Language} !^de [NC]
RewriteRule ^$ /fr/ [R]
分享名稱:創(chuàng)新互聯(lián)Angular教程:Angular 部署多個語言環(huán)境
網(wǎng)站路徑:http://www.dlmjj.cn/article/cdicodc.html


咨詢
建站咨詢
