Advertisement
Guest User

Untitled

a guest
May 31st, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. /**
  2. * Usage:
  3. import Resx = require("i18n");
  4. let en = Resx("en");
  5. en.foo = "bar";
  6. let enUs = Resx("en-US");
  7. should.equal(en.foo, "bar");
  8. should.equal(enUs.foo, "bar");
  9. en.foo = "en-foo";
  10. should.equal(en.foo, "en-foo", "en test 1");
  11. should.equal(enUs.foo, "en-foo", "en-us test 1");
  12. enUs.foo = "en-us-foo";
  13. should.equal(en.foo, "en-foo", "en test 2");
  14. should.equal(enUs.foo, "en-us-foo", "en-us test 2");
  15. */
  16. class i18n {
  17. static get(locale: string) {
  18. let factory = i18n[locale];
  19. if (!factory) {
  20. switch (locale.length) {
  21. case 5:
  22. factory = i18n[locale] = Object.create(i18n.get(locale.substring(0, 2)));
  23. break;
  24. case 2:
  25. default:
  26. factory = i18n[locale] = {};
  27. break;
  28. }
  29. }
  30. return factory;
  31. }
  32. }
  33.  
  34. export = i18n.get;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement