Example #1
0
    it('changes the default locale', function () {
      formatMessage.setup({ locale: 'ar' })
      var pattern = '{n,plural,few{few}other{other}}'
      var message = formatMessage(pattern, { n: 3 })
      formatMessage.setup({ locale: 'en' })

      expect(message).to.equal('few')
    })
Example #2
0
 it('adds custom formats', function () {
   formatMessage.setup({ formats: {
     number: { perc: {
       style: 'percent',
       maximumSignificantDigits: 1
     } },
     date: { day: {
       day: '2-digit'
     } },
     time: { minute: {
       hour: 'numeric',
       minute: 'numeric'
     } },
     missingTranslation: 'warning'
   } })
   var message = formatMessage('{ n, number, perc }', { n: 0.3672 })
     .replace(/\s+/g, '') // IE adds space
   expect(message).to.equal('40%')
   message = formatMessage('{ d, date, day }', { d: new Date('2015/10/19') })
     .replace(/[^\x00-\x7F]/g, '') // IE adds ltr marks
   expect(message).to.equal('19')
   message = formatMessage('{ t, time, minute }', { t: new Date('2015/10/19 5:06') })
     .replace(/[^\x00-\x7F]/g, '') // IE adds ltr marks
   expect(message).to.match(/^5:06/)
 })
Example #3
0
    it('can throw on missing', function () {
      formatMessage.setup({
        translations: { en: {} },
        missingTranslation: 'error'
      })

      expect(function () {
        var pattern = 'error-test'
        formatMessage(pattern)
      }).to.throw()

      formatMessage.setup({
        missingTranslation: 'warning',
        translations: null
      })
    })
Example #4
0
    it('changes the missing translation behavior', function () {
      formatMessage.setup({
        locale: 'en',
        translations: { en: {} },
        missingTranslation: 'warning',
        missingReplacement: '!!!'
      })
      var warn = console.warn
      // capturing error message is fickle in node
      console.warn = function () {}

      var id = 'test'
      var pattern = 'translation-test'
      var message = formatMessage({ id: id, default: pattern })
      console.warn = warn
      formatMessage.setup({ missingReplacement: null, translations: null })

      expect(message).to.equal('!!!')
    })
 /**
  *  @function
  *  @description Sets the desired locale as the current locale. This will also
  *    set all I18n instances to the same locale, as well as set formatMessage to use
  *    the same locale.
  *  @param {String} locale
  *  @return {Promise}
  */
 async setLocale(locale) {
   await I18n.setLocale(locale);
   formatMessage.setup({
     locale: this.currentLocale === PSEUDO_LOCALE ? DEFAULT_LOCALE : this.currentLocale,
   });
   this.store.dispatch({
     type: this.actionTypes.setLocale,
     locale,
   });
 }
Example #6
0
    it('changes the translation', function () {
      formatMessage.setup({
        locale: 'en',
        translations: { en: {
          'trans-test': { message: 'test-success' },
          'trans-test2': 'test-success2'
        } },
        missingTranslation: 'ignore',
        generateId: function (pattern) { return pattern }
      })
      // use variable to avoid inlining
      var pattern = 'trans-test'
      var message = formatMessage(pattern)
      var pattern2 = 'trans-test2'
      var message2 = formatMessage(pattern2)

      expect(message).to.equal('test-success')
      expect(message2).to.equal('test-success2')
    })
/* global Locale */
/* eslint no-undef: "error" */
require('Locale')
require('Locale/Gettext')

_.each(Tine.__translationData.msgs, function (msgs, category) {
  Locale.Gettext.prototype._msgs[category] = new Locale.Gettext.PO(msgs)
})

let gettext = new Locale.Gettext()
gettext.textdomain('Calendar')

// NOTE: we use gettext tooling for template selection
//       as there is almost no tooling for icu-messages out there
FormatMessage.setup({
  missingTranslation: 'ignore'
})

// auto template selection with gettext
Vue.prototype.formatMessage = function (template) {
  arguments[0] = gettext._hidden(template)
  return FormatMessage.apply(FormatMessage, arguments)
}
_.assign(Vue.prototype.formatMessage, FormatMessage)
// to translate strings which should not go into po files
Vue.prototype.fmHidden = Vue.prototype.formatMessage

Vue.config.productionTip = false

Vue.use(Tine20, {})
Example #8
0
 expect(function () { formatMessage.setup() }).to.not.throw()