Advertisement
Guest User

Untitled

a guest
Jul 4th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from '@angular/core';
  2. import { TranslationService } from './translation.service';
  3.  
  4. @Injectable()
  5. export class DictionaryService {
  6.  
  7.   public static add_cart: string = DictionaryService.getText('add_cart');
  8.   public static adults: string = DictionaryService.getText('adults');
  9.   public static before: string = DictionaryService.getText('before');
  10.   public static breadcrumb_1: string = DictionaryService.getText('breadcrumb_1');
  11.   public static breadcrumb_2: string = DictionaryService.getText('breadcrumb_2');
  12.   public static breadcrumb_3: string = DictionaryService.getText('breadcrumb_3');
  13.   public static breadcrumb_4: string = DictionaryService.getText('breadcrumb_4');
  14.   public static children: string = DictionaryService.getText('children');
  15.   public static children_age: string = DictionaryService.getText('children_age');
  16.   public static continue: string = DictionaryService.getText('continue');
  17.   public static date: string = DictionaryService.getText('date');
  18.   public static discount_coupon_placeholder: string = DictionaryService.getText('discount_coupon_placeholder');
  19.   public static discount_coupon_text: string = DictionaryService.getText('discount_coupon_text');
  20.   public static email: string = DictionaryService.getText('email');
  21.   public static final_price: string = DictionaryService.getText('final_price');
  22.   public static footer_contact: string = DictionaryService.getText('footer_contact');
  23.   public static footer_privacy: string = DictionaryService.getText('footer_privacy');
  24.   public static footer_rights: string = DictionaryService.getText('footer_rights');
  25.   public static footer_terms: string = DictionaryService.getText('footer_terms');
  26.   public static header_secure: string = DictionaryService.getText('header_secure');
  27.   public static header_title: string = DictionaryService.getText('header_title');
  28.   public static invoice: string = DictionaryService.getText('invoice');
  29.   public static nameinput: string = DictionaryService.getText('name');
  30.   public static order_message_1: string = DictionaryService.getText('order_message_1');
  31.   public static order_message_2: string = DictionaryService.getText('order_message_2');
  32.   public static pay_now: string = DictionaryService.getText('pay_now');
  33.   public static payments_methods: string = DictionaryService.getText('payments_methods');
  34.   public static personal_information: string = DictionaryService.getText('personal_information');
  35.   public static price: string = DictionaryService.getText('price');
  36.   public static print_tickets: string = DictionaryService.getText('print_tickets');
  37.   public static quantity: string = DictionaryService.getText('quantity');
  38.   public static summary: string = DictionaryService.getText('summary');
  39.   public static surname: string = DictionaryService.getText('surname');
  40.   public static taxes_text: string = DictionaryService.getText('taxes_text');
  41.   public static terms_read: string = DictionaryService.getText('terms_read');
  42.   public static thank_you: string = DictionaryService.getText('thank_you');
  43.   public static thank_you_order: string = DictionaryService.getText('thank_you_order');
  44.   public static total_cost: string = DictionaryService.getText('total_cost');
  45.   public static unity_price: string = DictionaryService.getText('unity_price');
  46.   public static you_save: string = DictionaryService.getText('you_save');
  47.   public static your_options: string = DictionaryService.getText('your_options');
  48.  
  49.   constructor(private translationService: TranslationService) {
  50.    }
  51.  
  52.    public static getTranslations() {
  53.     const arr = JSON.parse(localStorage.getItem('translation')) || null;
  54.  
  55.     if (arr == null) {
  56.       new TranslationService().readTranslations(this.callback);
  57.     } else {
  58.       return arr;
  59.     }
  60.   }
  61.  
  62.   static callback = (item: any) => {
  63.     localStorage.setItem('translation', JSON.stringify(item));
  64.     window.location.reload();
  65.   }
  66.  
  67.   public static getText(search: string): string {
  68.     const lang = localStorage.getItem('lang') || 'EN';
  69.     const arr = this.getTranslations();
  70.  
  71.     const word = arr.filter(function(x) {
  72.       if (x.Identifier === search) {
  73.         return x;
  74.       }
  75.     });
  76.  
  77.     if (lang === 'ES') {
  78.       return word[0].Spanish;
  79.     } else {
  80.       return word[0].English;
  81.     }
  82.   }
  83.  
  84. }
  85.  
  86.  
  87.  
  88. // WEBPACK FOOTER //
  89. // ./src/app/service/dictionary.service.ts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement