LP#1775466 Ang6 locale switching
authorBill Erickson <berickxx@gmail.com>
Tue, 31 Jul 2018 19:30:41 +0000 (15:30 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 5 Sep 2018 14:05:23 +0000 (10:05 -0400)
* Add the locale to the URL path
* Support switching locales via the eg_locale cookie value
* Add docs on building a (for example) fr-CA locale bundle
* Add apache config examples to support locales.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/examples/apache_24/eg_vhost.conf.in
Open-ILS/src/eg2/README.adoc
Open-ILS/src/eg2/angular.json
Open-ILS/src/eg2/package.json
Open-ILS/src/eg2/src/locale/.gitkeep [new file with mode: 0644]

index c8251b7..b8b3acf 100644 (file)
@@ -824,7 +824,32 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT]
 #RewriteCond %{HTTPS} off
 #RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R,L]
 
-<Directory "/openils/var/web/eg2">
-    FallbackResource /eg2/index.html
+# ------------------------------------------------------------------------
+# /eg2/ client setup and locale configuration.
+#
+# If a valid locale cookie is present that does not match the current
+# path, redirect to the requested locale path.
+# Otherwise, if no locale is active, redirect to the default locale.
+
+# fr-CA
+#RewriteCond %{REQUEST_URI} ^/eg2/
+#RewriteCond %{REQUEST_URI} !^/eg2/fr-CA/
+#RewriteCond %{HTTP_COOKIE} eg_locale=fr_ca
+#RewriteRule ^/eg2/(.*) https://%{HTTP_HOST}/eg2/fr-CA/$1 [R=307,L]
+
+# Default / en-US.
+# No alternate supported cookie provided.
+#RewriteCond %{REQUEST_URI}  ^/eg2/
+#RewriteCond %{REQUEST_URI}  !^/eg2/([a-z]{2}-[A-Z]{2})/
+#RewriteRule ^/eg2/(.*) https://%{HTTP_HOST}/eg2/en-US/$1 [R=307,L]
+
+# en-US build
+# This is the only required configuration when only using the default locale.
+<Directory "/openils/var/web/eg2/en-US">
+    FallbackResource /eg2/en-US/index.html
 </Directory>
 
+# fr-CA build
+#<Directory "/openils/var/web/eg2/fr-CA">
+#    FallbackResource /eg2/fr-CA/index.html
+#</Directory>
index 9bd4668..6b73bc1 100644 (file)
@@ -94,6 +94,20 @@ npm run test
 ng lint
 ---------------------------------------------------------------------
 
+=== OPTIONAL: Building for an alternate locale
+
+* Using fr-CA as an example.
+* An fr-CA configuration is supplied by default.
+* Currently translation builds are only available on --prod build mode.
+* Uncomment the locale lines in eg_vhost.conf and restart apache.
+
+[source,sh]
+---------------------------------------------------------------------
+npm run build-translations
+# Modify some <target> entries in src/locale/messages.fr-CA.xlf to test
+ng build --configuration=production-fr-CA --output-path ../../web/eg2/fr-CA --deploy-url /eg2/fr-CA/ --base-href /eg2/fr-CA
+---------------------------------------------------------------------
+
 === Deploy
 
 Build and install Evergreen code as usual.  Restart Evergreen and Apache.
index 9e21ced..e50c8db 100644 (file)
@@ -11,9 +11,9 @@
         "build": {
           "builder": "@angular-devkit/build-angular:browser",
           "options": {
-            "baseHref": "/eg2",
-            "deployUrl": "/eg2/",
-            "outputPath": "../../web/eg2",
+            "baseHref": "/eg2/en-US",
+            "deployUrl": "/eg2/en-US/",
+            "outputPath": "../../web/eg2/en-US",
             "index": "src/index.html",
             "main": "src/main.ts",
             "tsConfig": "src/tsconfig.app.json",
                   "with": "src/environments/environment.prod.ts"
                 }
               ]
+            },
+            "production-fr-CA": {
+              "optimization": true,
+              "outputHashing": "all",
+              "sourceMap": false,
+              "extractCss": true,
+              "namedChunks": false,
+              "aot": true,
+              "extractLicenses": true,
+              "vendorChunk": false,
+              "buildOptimizer": true,
+              "i18nFile": "src/locale/messages.fr-CA.xlf",
+              "i18nFormat": "xlf",
+              "i18nLocale": "fr-CA",
+              "i18nMissingTranslation": "ignore",
+              "fileReplacements": [
+                {
+                  "replace": "src/environments/environment.ts",
+                  "with": "src/environments/environment.prod.ts"
+                }
+              ]
             }
           }
         },
index bf6a870..f43925c 100644 (file)
@@ -9,7 +9,8 @@
     "test": "npm run create-mock-idl; ng test",
     "lint": "ng lint",
     "e2e": "ng e2e",
-    "create-mock-idl": "cd src/test_data && perl idl2js.pl"
+    "create-mock-idl": "cd src/test_data && perl idl2js.pl",
+    "build-translations": "ng xi18n --output-path locale && xliffmerge fr-CA"
   },
   "private": true,
   "dependencies": {
     "karma-jasmine": "~1.1.0",
     "karma-jasmine-html-reporter": "^0.2.2",
     "karma-phantomjs-launcher": "^1.0.4",
+    "ngx-i18nsupport": "^0.16.3",
     "protractor": "~5.1.2",
     "ts-node": "~3.2.0",
     "tslint": "~5.7.0",
     "typescript": "2.7.2"
+  },
+  "xliffmergeOptions": {
+    "srcDir": "src/locale",
+    "genDir": "src/locale",
+    "i18nFile": "messages.xlf",
+    "i18nBaseFile": "messages",
+    "i18nFormat": "xlf",
+    "encoding": "UTF-8",
+    "defaultLanguage": "en",
+    "languages": ["en", "fr-CA"],
+    "removeUnusedIds": true,
+    "supportNgxTranslate": false,
+    "ngxTranslateExtractionPattern": "@@|ngx-translate",
+    "useSourceAsTarget": true,
+    "targetPraefix": "",
+    "targetSuffix": "",
+    "beautifyOutput": false,
+    "allowIdChange": false,
+    "autotranslate": false,
+    "apikey": "",
+    "apikeyfile": "",
+    "verbose": false,
+    "quiet": false
   }
 }
diff --git a/Open-ILS/src/eg2/src/locale/.gitkeep b/Open-ILS/src/eg2/src/locale/.gitkeep
new file mode 100644 (file)
index 0000000..e69de29