]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
Fix i18n in components
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / config / edit-custom-config / edit-custom-config.component.ts
index 2ab371cbbdc0c2e457d82f9f389ad94fc729565f..73ff4b7bbe6551ecb68e51670f2ec2c6d8ff826f 100644 (file)
@@ -8,12 +8,15 @@ import { FormReactive, USER_VIDEO_QUOTA } from '@app/shared'
 import {
   ADMIN_EMAIL,
   CACHE_PREVIEWS_SIZE,
-  INSTANCE_NAME, INSTANCE_SHORT_DESCRIPTION,
+  INSTANCE_NAME,
+  INSTANCE_SHORT_DESCRIPTION,
+  SERVICES_TWITTER_USERNAME,
   SIGNUP_LIMIT,
   TRANSCODING_THREADS
 } from '@app/shared/forms/form-validators/custom-config'
 import { NotificationsService } from 'angular2-notifications'
 import { CustomConfig } from '../../../../../../shared/models/server/custom-config.model'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 
 @Component({
   selector: 'my-edit-custom-config',
@@ -49,6 +52,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
     instanceTerms: '',
     instanceDefaultClientRoute: '',
     instanceDefaultNSFWPolicy: '',
+    servicesTwitterUsername: '',
     cachePreviewsSize: '',
     signupLimit: '',
     adminEmail: '',
@@ -60,6 +64,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
   validationMessages = {
     instanceShortDescription: INSTANCE_SHORT_DESCRIPTION.MESSAGES,
     instanceName: INSTANCE_NAME.MESSAGES,
+    servicesTwitterUsername: SERVICES_TWITTER_USERNAME,
     cachePreviewsSize: CACHE_PREVIEWS_SIZE.MESSAGES,
     signupLimit: SIGNUP_LIMIT.MESSAGES,
     adminEmail: ADMIN_EMAIL.MESSAGES,
@@ -75,7 +80,8 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
     private notificationsService: NotificationsService,
     private configService: ConfigService,
     private serverService: ServerService,
-    private confirmService: ConfirmService
+    private confirmService: ConfirmService,
+    private i18n: I18n
   ) {
     super()
   }
@@ -92,6 +98,8 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
       instanceTerms: [ '' ],
       instanceDefaultClientRoute: [ '' ],
       instanceDefaultNSFWPolicy: [ '' ],
+      servicesTwitterUsername: [ '', SERVICES_TWITTER_USERNAME.VALIDATORS ],
+      servicesTwitterWhitelisted: [ ],
       cachePreviewsSize: [ '', CACHE_PREVIEWS_SIZE.VALIDATORS ],
       signupEnabled: [ ],
       signupLimit: [ '', SIGNUP_LIMIT.VALIDATORS ],
@@ -129,7 +137,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
           this.forceCheck()
         },
 
-        err => this.notificationsService.error('Error', err.message)
+        err => this.notificationsService.error(this.i18n('Error'), err.message)
       )
   }
 
@@ -152,11 +160,15 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
     if (customizations.length !== 0) {
       const customizationsText = customizations.join('/')
 
-      const message = `You set custom ${customizationsText}. ` +
-        'This could lead to security issues or bugs if you do not understand it. ' +
-        'Are you sure you want to update the configuration?'
-      const label = `Please type "I understand the ${customizationsText} I set" to confirm.`
-      const expectedInputValue = `I understand the ${customizationsText} I set`
+      // FIXME: i18n service does not support string concatenation
+      const message = this.i18n('You set custom {{customizationsText}}. ', { customizationsText }) +
+        this.i18n('This could lead to security issues or bugs if you do not understand it. ') +
+        this.i18n('Are you sure you want to update the configuration?')
+      const label = this.i18n(
+        'Please type "I understand the {{customizationsText}} I set" to confirm.',
+        { customizationsText }
+      )
+      const expectedInputValue = this.i18n('I understand the {{customizationsText}} I set', { customizationsText })
 
       const confirmRes = await this.confirmService.confirmWithInput(message, label, expectedInputValue)
       if (confirmRes === false) return
@@ -175,6 +187,12 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
           css: this.form.value['customizationCSS']
         }
       },
+      services: {
+        twitter: {
+          username: this.form.value['servicesTwitterUsername'],
+          whitelisted: this.form.value['servicesTwitterWhitelisted']
+        }
+      },
       cache: {
         previews: {
           size: this.form.value['cachePreviewsSize']
@@ -213,10 +231,10 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
 
           this.updateForm()
 
-          this.notificationsService.success('Success', 'Configuration updated.')
+          this.notificationsService.success(this.i18n('Success'), this.i18n('Configuration updated.'))
         },
 
-        err => this.notificationsService.error('Error', err.message)
+        err => this.notificationsService.error(this.i18n('Error'), err.message)
       )
   }
 
@@ -228,6 +246,8 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
       instanceTerms: this.customConfig.instance.terms,
       instanceDefaultClientRoute: this.customConfig.instance.defaultClientRoute,
       instanceDefaultNSFWPolicy: this.customConfig.instance.defaultNSFWPolicy,
+      servicesTwitterUsername: this.customConfig.services.twitter.username,
+      servicesTwitterWhitelisted: this.customConfig.services.twitter.whitelisted,
       cachePreviewsSize: this.customConfig.cache.previews.size,
       signupEnabled: this.customConfig.signup.enabled,
       signupLimit: this.customConfig.signup.limit,