1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-11-28 08:58:49 +02:00

updating building and translations

This commit is contained in:
Patrik J. Braun 2021-04-17 18:32:32 +02:00
parent ddf516b399
commit e83ba7c5fa
14 changed files with 14806 additions and 15038 deletions

View File

@ -125,12 +125,9 @@ apt-get install build-essential libkrb5-dev gcc g++
## 2. Translate the page to your own language
1. [Install Pigallery2](#121-b-install-from-source) from source (with the release it won't work)
2. add your language e.g: fr
```bash
npm run add-translation -- --fr
```
it creates a new `messages.fr.xls` file at `src/frontend/translate` folder,
it will already contain dummy translation with google translate.
3. 'fix' the dummy translation
* copy `src/frontend/translate/messages.en.xls` to `src/frontend/translate/messages.fr.xls`
* add the new translation to the `angular.json` `projects->pigallery2->i18n->locales` section
3. translate the file by updating the `<target>` tags
4. test if it works:
build and start the app
```bash

View File

@ -9,13 +9,52 @@
"projectType": "application",
"schematics": {},
"prefix": "app",
"i18n": {
"sourceLocale": {
"code": "en",
"baseHref": ""
},
"locales": {
"es": {
"baseHref": "",
"translation": "src/frontend/translate/messages.es.xlf"
},
"fr": {
"baseHref": "",
"translation": "src/frontend/translate/messages.fr.xlf"
},
"hu": {
"baseHref": "",
"translation": "src/frontend/translate/messages.hu.xlf"
},
"it": {
"baseHref": "",
"translation": "src/frontend/translate/messages.it.xlf"
},
"ro": {
"baseHref": "",
"translation": "src/frontend/translate/messages.ro.xlf"
},
"ru": {
"baseHref": "",
"translation": "src/frontend/translate/messages.ru.xlf"
},
"sv": {
"baseHref": "",
"translation": "src/frontend/translate/messages.sv.xlf"
}
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"localize": true,
"aot": true,
"crossOrigin": "anonymous",
"outputPath": "dist",
"index": "src/frontend/index.html",
"progress": true,
"main": "src/frontend/main.ts",
"tsConfig": "src/frontend/tsconfig.app.json",
"polyfills": "src/frontend/polyfills.ts",
@ -29,15 +68,22 @@
"ngx-toastr/toastr.css",
"src/frontend/styles.css"
],
"scripts": []
"scripts": [],
"i18nMissingTranslation": "warning"
},
"configurations": {
"dev": {
"localize": [
"en"
],
"outputPath": "dist",
"watch": true
},
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,

View File

@ -35,7 +35,7 @@ const getSwitch = (name: string, def: string = null): string => {
return def;
};
gulp.task('build-backend', function () {
gulp.task('build-backend', function() {
return gulp.src([
'src/common/**/*.ts',
'src/backend/**/*.ts',
@ -95,30 +95,13 @@ const resetAppModule = async (language: string) => {
const createFrontendTask = (type: string, language: string, script: string) => {
gulp.task(type, async (cb) => {
let error;
try {
// TODO: remove this once i18n-pollify is removed from the project
// Adding filtered translation as webpack would pack all translations into the created release
await createDynamicTranslationFile(language);
await setDynTransFileAtAppModule(language);
const {stdout, stderr} = await execPr(script);
console.log(stdout);
console.error(stderr);
} catch (e) {
console.error(e);
error = e;
} finally {
try {
await resetAppModule(language);
} catch (e) {
}
try {
await removeDynamicTranslationFile(language);
} catch (e) {
}
cb(error);
cb(e);
}
});
};
@ -152,27 +135,14 @@ const getLanguages = () => {
};
gulp.task('build-frontend', (() => {
const languages = getLanguages().filter((l) => {
return l !== 'en';
});
const tasks = [];
createFrontendTask('build-frontend-release default', 'en',
'ng build --aot --prod --output-path=./release/dist --no-progress --i18n-locale=en' +
' --i18n-format xlf --i18n-file src/frontend/' + translationFolder + '/messages.en.xlf' +
' --i18n-missing-translation warning');
createFrontendTask('build-frontend-release default', 'all',
'ng build --prod --no-progress');
tasks.push('build-frontend-release default');
for (let i = 0; i < languages.length; i++) {
createFrontendTask('build-frontend-release ' + languages[i], languages[i],
'ng build --aot --prod --output-path=./release/dist/' + languages[i] +
' --no-progress --i18n-locale=' + languages[i] +
' --i18n-format xlf --i18n-file src/frontend/' + translationFolder + '/messages.' + languages[i] + '.xlf' +
' --i18n-missing-translation warning');
tasks.push('build-frontend-release ' + languages[i]);
}
return gulp.series(...tasks);
})());
gulp.task('copy-static', function () {
gulp.task('copy-static', function() {
return gulp.src([
'src/backend/model/diagnostics/blank.jpg',
'README.md',
@ -181,7 +151,7 @@ gulp.task('copy-static', function () {
.pipe(gulp.dest('./release'));
});
gulp.task('copy-package', function () {
gulp.task('copy-package', function() {
return gulp.src([
'package.json'], {base: '.'})
.pipe(jeditor((json: {
@ -225,7 +195,7 @@ gulp.task('copy-package', function () {
});
gulp.task('zip-release', function () {
gulp.task('zip-release', function() {
return gulp.src(['release/**/*'], {base: './release'})
.pipe(zip('pigallery2.zip'))
.pipe(gulp.dest('.'));
@ -235,27 +205,17 @@ gulp.task('create-release', gulp.series('build-frontend', 'build-backend', 'copy
const simpleBuild = (isProd: boolean) => {
const languages = getLanguages().filter((l) => {
return l !== 'en';
});
const tasks = [];
let cmd = 'ng build --aot ';
let cmd = 'ng build ';
if (isProd) {
cmd += ' --prod --no-extract-licenses ';
}
createFrontendTask('build-frontend default', 'en', cmd + '--output-path=./dist --no-progress --no-progress --i18n-locale en' +
' --i18n-format=xlf --i18n-file=src/frontend/' + translationFolder + '/messages.en.xlf' + ' --i18n-missing-translation warning');
tasks.push('build-frontend default');
if (!process.env.CI) { // don't build languages if running in CI
for (let i = 0; i < languages.length; i++) {
createFrontendTask('build-frontend ' + languages[i], languages[i], cmd +
'--output-path=./dist/' + languages[i] +
' --no-progress --i18n-locale ' + languages[i] +
' --i18n-format=xlf --i18n-file=src/frontend/' + translationFolder +
'/messages.' + languages[i] + '.xlf' + ' --i18n-missing-translation warning');
tasks.push('build-frontend ' + languages[i]);
}
if (!process.env.CI) {
createFrontendTask('build-frontend default', 'all', cmd);
} else {
createFrontendTask('build-frontend default', 'all', cmd + '--localize=false');
}
tasks.push('build-frontend default');
return gulp.series(...tasks);
};
@ -263,7 +223,7 @@ gulp.task('extract-locale', async (cb) => {
console.log('creating source translation file: locale.source.xlf');
try {
{
const {stdout, stderr} = await execPr('ng extract-i18n --out-file=./../../locale.source.xlf --i18n-format=xlf --i18n-locale=en',
const {stdout, stderr} = await execPr('ng extract-i18n --out-file=locale.source.xlf --format=xlf',
{maxBuffer: 1024 * 1024});
console.log(stdout);
console.error(stderr);
@ -299,12 +259,15 @@ const translate = async (list: any[], cb: (err?: any) => void) => {
const merge = async (list: any[], cb: (err?: any) => void) => {
try {
const localsStr = '"[\\"' + list.join('\\",\\"') + '\\"]"';
const {stdout, stderr} = await execPr('xlf-google-translate ' +
const command = 'xlf-google-translate ' +
'--method="extend-only" ' +
'--source-lang="en" ' +
'--source-file="./locale.source.xlf" ' +
'--destination-filename="messages" ' +
'--destination-folder="./src/frontend/"' + translationFolder + ' --destination-languages=' + localsStr);
'--destination-folder="./src/frontend/' + translationFolder + '" ' +
'--destination-languages=' + localsStr;
console.log(command);
const {stdout, stderr} = await execPr(command);
console.log(stdout);
console.error(stderr);
cb();
@ -314,10 +277,10 @@ const merge = async (list: any[], cb: (err?: any) => void) => {
}
};
gulp.task('update-translation-only', function (cb) {
gulp.task('update-translation-only', function(cb) {
translate(getLanguages(), cb).catch(console.error);
});
gulp.task('merge-translation-only', function (cb) {
gulp.task('merge-translation-only', function(cb) {
merge(getLanguages(), cb).catch(console.error);
});
@ -346,7 +309,7 @@ gulp.task('add-translation-only', (cb) => {
});
gulp.task('generate-man', async (cb) => {
const defCFG = ConfigClassBuilder.attachInterface(new PrivateConfigClass());
const defCFG = ConfigClassBuilder.attachInterface(new PrivateConfigClass());
defCFG.Server.sessionSecret = [];
let txt = '# Pigallery 2 man page\n';
txt += 'pigallery2 uses [typeconfig](https://github.com/bpatrik/typeconfig) for configuration\n\n';

32
package-lock.json generated
View File

@ -5316,20 +5316,14 @@
},
"dependencies": {
"get-stream": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz",
"integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==",
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
"integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
"dev": true,
"requires": {
"pump": "^3.0.0"
}
},
"http-cache-semantics": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz",
"integrity": "sha512-TcIMG3qeVLgDr1TEd2XvHaTnMPwYQUQMIBLy+5pLSDKYFc7UIqj39w8EGzZkaxoLv/l2K8HaI0t5AVA+YYgUew==",
"dev": true
},
"lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
@ -7636,9 +7630,9 @@
}
},
"defer-to-connect": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.1.tgz",
"integrity": "sha512-J7thop4u3mRTkYRQ+Vpfwy2G5Ehoy82I14+14W4YMDLKdWloI9gSzRbV30s/NckQGVJtPkWNcW4oMAUigTdqiQ==",
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz",
"integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==",
"dev": true
},
"define-properties": {
@ -24358,20 +24352,20 @@
}
},
"xlf-google-translate": {
"version": "1.0.0-beta.19",
"resolved": "https://registry.npmjs.org/xlf-google-translate/-/xlf-google-translate-1.0.0-beta.19.tgz",
"integrity": "sha512-zeZTvH3ijeh0/F73jrKr4/Ojr61ds6NHP+KN792uamMzCY3Fv0wfjLXSzdXINXEK+CKKNyV333i6zPMzt7fz0Q==",
"version": "1.0.0-beta.21",
"resolved": "https://registry.npmjs.org/xlf-google-translate/-/xlf-google-translate-1.0.0-beta.21.tgz",
"integrity": "sha512-gKk289jY3cBYf0uJg6jxqOqGg8HFbL3YohwM9RobT0FgD3hIR+Xo6spNeseGtYEXXsiU7B4ri1UOMqlj17vDTQ==",
"dev": true,
"requires": {
"@k3rn31p4nic/google-translate-api": "1.1.0",
"typeconfig": "1.0.9",
"typeconfig": "2.0.15",
"xml2js": "0.4.23"
},
"dependencies": {
"typeconfig": {
"version": "1.0.9",
"resolved": "https://registry.npmjs.org/typeconfig/-/typeconfig-1.0.9.tgz",
"integrity": "sha512-s8iCnCTSVNP6S7yF6KdkyhbvV0BDmPE/RnJOZf77sjMdfB5B/QlqrFFQWmnz+818xsP38bieD5OcP1iqzUKW/A==",
"version": "2.0.15",
"resolved": "https://registry.npmjs.org/typeconfig/-/typeconfig-2.0.15.tgz",
"integrity": "sha512-KpngjnOktNxnS9dksBzQnKn7XTXlcvxouWrNYrZnZDupX/bXDjF8vaaU1AokpqE4Jb+ectygUUh10erxEZhQDQ==",
"dev": true,
"requires": {
"optimist": "0.6.1"

View File

@ -16,8 +16,7 @@
"test": "ng test && nyc mocha --recursive test",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"start": "node ./src/backend/index",
"run-dev": "ng build --aot --watch --output-path=./dist --i18n-locale en --i18n-file src/frontend/translate/messages.en.xlf --i18n-missing-translation warning",
"run-dev-hu": "ng build --aot --watch --output-path=./dist --i18n-locale hu --i18n-file src/frontend/translate/messages.hu.xlf --i18n-missing-translation warning",
"run-dev": "ng build --configuration=dev",
"build-stats": "ng build --aot --prod --stats-json --output-path=./dist --i18n-locale en --i18n-file src/frontend/translate/messages.en.xlf --i18n-missing-translation warning",
"merge-new-translation": "gulp merge-new-translation",
"add-translation": "gulp add-translation",
@ -135,7 +134,7 @@
"ts-node": "9.1.1",
"tslint": "6.1.3",
"typescript": "4.1.5",
"xlf-google-translate": "1.0.0-beta.19",
"xlf-google-translate": "1.0.0-beta.21",
"xml2js": "0.4.23",
"zone.js": "0.11.4"
},

View File

@ -26,24 +26,20 @@ declare global {
export class PublicRouter {
public static route(app: Express) {
const setLocale = (req: Request, res: Response, next: Function) => {
let localePath = '';
public static route(app: Express): void {
const setLocale = (req: Request, res: Response, next: NextFunction) => {
let selectedLocale = req['locale'];
if (req.cookies && req.cookies[CookieNames.lang]) {
if (Config.Client.languages.indexOf(req.cookies[CookieNames.lang]) !== -1) {
selectedLocale = req.cookies[CookieNames.lang];
}
}
if (selectedLocale !== 'en') {
localePath = selectedLocale;
}
res.cookie(CookieNames.lang, selectedLocale);
req['localePath'] = localePath;
req['localePath'] = selectedLocale;
next();
};
const renderIndex = (req: Request, res: Response, next: Function) => {
const renderIndex = (req: Request, res: Response, next: NextFunction) => {
ejs.renderFile(path.join(ProjectPath.FrontendFolder, req['localePath'], 'index.html'),
res.tpl, (err, str) => {
if (err) {
@ -69,14 +65,14 @@ export class PublicRouter {
res.tpl.user = null;
if (req.session.user) {
res.tpl.user = <UserDTO>{
res.tpl.user = {
id: req.session.user.id,
name: req.session.user.name,
csrfToken: req.session.user.csrfToken,
role: req.session.user.role,
usedSharingKey: req.session.user.usedSharingKey,
permissions: req.session.user.permissions
};
} as UserDTO;
if (!res.tpl.user.csrfToken && req.csrfToken) {
res.tpl.user.csrfToken = req.csrfToken();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff