i18n.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Utilities: A classic collection of JavaScript utilities
  3. * Copyright 2112 Matthew Eernisse ([email protected])
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. var i18n = require('../lib/i18n')
  19. , assert = require('assert')
  20. , tests
  21. , inst = {};
  22. tests = {
  23. 'before': function () {
  24. i18n.loadLocale('en-us', {foo: 'FOO', bar: 'BAR', baz: 'BAZ'});
  25. i18n.loadLocale('ja-jp', {foo: 'フー', bar: 'バー'});
  26. inst.en = new i18n.I18n('en-us');
  27. inst.jp = new i18n.I18n('ja-jp');
  28. inst.de = new i18n.I18n('de-de');
  29. }
  30. , 'test default-locale fallback, defined strings': function () {
  31. var expected = 'BAZ'
  32. , actual = inst.jp.t('baz');
  33. assert.equal(expected, actual);
  34. }
  35. , 'test default-locale fallback, no defined strings': function () {
  36. var expected = 'BAZ'
  37. , actual = inst.de.t('baz');
  38. assert.equal(expected, actual);
  39. }
  40. , 'test key lookup, default-locale': function () {
  41. var expected = 'FOO'
  42. , actual = inst.en.t('foo');
  43. assert.equal(expected, actual);
  44. }
  45. , 'test key lookup, non-default-locale': function () {
  46. var expected = 'フー'
  47. , actual = inst.jp.t('foo');
  48. assert.equal(expected, actual);
  49. }
  50. };
  51. module.exports = tests;