The issue at hand is that the primary index.html
file, along with some other files, is not equipped to function as a template, hindering certain actions such as translation. For more details, please refer to this specific problem.
Despite this limitation, I endeavored to tackle the challenge myself:
To address this, create a translated version of your main index.html
and save it within a folder named after the corresponding rtl
language (fa
in my situation):
src/fa/index.html:
<!doctype html>
<html lang="fa" dir="rtl">
<head>
<meta charset="utf-8">
<title>عنوان برنامه</title>
<base href="/fa/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#1976d2">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
</head>
<body>
<app-root></app-root>
<noscript>برای ادامه استفاده از این برنامه لازم است JavaScript را فعال کنید.</noscript>
</body>
</html>
Note elements like lang="fa"
, dir="rtl"
, and content in native language.
In your relevant build configurations (e.g., production-fa
and fa
) within your angular.json
file, include:
"index": "src/fa/index.html"
Success!
You can apply similar strategies for other languages (even ltr
s! Due to adjustments made in index.html
).
For better comprehension, I have provided pertinent build scripts in my package.json
file:
"start-fa": "ng serve --configuration=fa",
"build-fa": "ng build --configuration=fa",
"build-prod-fa": "ng build --prod --configuration=production-fa",
Bonus: How about modifying the manifest.json
file for potential PWA installation?
The initial step mirrors the above process. Create a translated version located at src/fa/manifest.json
:
{
"dir": "rtl",
"lang": "fa",
"name": "نام بلند برنامه",
"short_name": "نام کوتاه",
"theme_color": ...
...
However, the subsequent step demands extra attention. Defining its path proved challenging for me. You may opt to substitute the original file (src/manifest.json
) with this new one. This action must be completed PRIOR to initiating the build process (not afterwards by replacing dist/.../manifest.json
; since @angular/service-worker
necessitates knowledge of the final state during the building phase). To do so in your package.json
:
"build-prod-fa": "cp src/fa/manifest.json src/manifest.json && ng build --prod --configuration=production-fa",
And remember to restore it to its default form (in my scenario where en
is the default language) prior to default production builds:
"build-prod": "cp src/en/manifest.json src/manifest.json && ng build --prod",
Please note that only production
builds are pivotal regarding the manifest.json
. As by default, serviceWorker
is exclusively enabled in these setups (refer to your angular.json
file).
I am aware this workaround is far from perfect. It entails modifying source files in various locations.