From 36acae1069248b1e6237d89b7f3e5edc8c943a2a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 31 Jul 2018 15:30:41 -0400 Subject: [PATCH] LP#1775466 Ang6 locale switching * 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 --- Open-ILS/examples/apache_24/eg_vhost.conf.in | 29 ++++++++++++++++++++++++++-- Open-ILS/src/eg2/README.adoc | 14 ++++++++++++++ Open-ILS/src/eg2/angular.json | 27 +++++++++++++++++++++++--- Open-ILS/src/eg2/package.json | 27 +++++++++++++++++++++++++- Open-ILS/src/eg2/src/locale/.gitkeep | 0 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 Open-ILS/src/eg2/src/locale/.gitkeep diff --git a/Open-ILS/examples/apache_24/eg_vhost.conf.in b/Open-ILS/examples/apache_24/eg_vhost.conf.in index c8251b7d2a..b8b3acf880 100644 --- a/Open-ILS/examples/apache_24/eg_vhost.conf.in +++ b/Open-ILS/examples/apache_24/eg_vhost.conf.in @@ -824,7 +824,32 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT] #RewriteCond %{HTTPS} off #RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R,L] - - 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. + + FallbackResource /eg2/en-US/index.html +# fr-CA build +# +# FallbackResource /eg2/fr-CA/index.html +# diff --git a/Open-ILS/src/eg2/README.adoc b/Open-ILS/src/eg2/README.adoc index 9bd4668aab..6b73bc1ac5 100644 --- a/Open-ILS/src/eg2/README.adoc +++ b/Open-ILS/src/eg2/README.adoc @@ -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 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. diff --git a/Open-ILS/src/eg2/angular.json b/Open-ILS/src/eg2/angular.json index 9e21ceddb2..e50c8db5f7 100644 --- a/Open-ILS/src/eg2/angular.json +++ b/Open-ILS/src/eg2/angular.json @@ -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", @@ -44,6 +44,27 @@ "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" + } + ] } } }, diff --git a/Open-ILS/src/eg2/package.json b/Open-ILS/src/eg2/package.json index bf6a870029..f43925c835 100644 --- a/Open-ILS/src/eg2/package.json +++ b/Open-ILS/src/eg2/package.json @@ -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": { @@ -48,9 +49,33 @@ "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 index 0000000000..e69de29bb2 -- 2.11.0