not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. // Localization component
  2. var Localization = {
  3. template: '<div/>',
  4. data: function() {
  5. return {
  6. l10n: null,
  7. code: null,
  8. dictionary: null,
  9. eventReceived: false
  10. }
  11. },
  12. mounted: function() {
  13. var vm = this;
  14. if (vm.l10n == null) {
  15. requirejs(["sugar-web/env", "webL10n"], function (env, webL10n) {
  16. env.getEnvironment(function(err, environment) {
  17. vm.l10n = webL10n;
  18. var defaultLanguage = (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) ? chrome.i18n.getUILanguage() : navigator.language;
  19. var language = environment.user ? environment.user.language : defaultLanguage;
  20. webL10n.language.code = language;
  21. window.addEventListener("localized", function() {
  22. if (!vm.eventReceived) {
  23. vm.code = language;
  24. vm.dictionary = vm.l10n.dictionary;
  25. vm.$emit("localized");
  26. vm.eventReceived = true;
  27. }
  28. });
  29. });
  30. });
  31. }
  32. },
  33. methods: {
  34. get: function(str) {
  35. if (!this.dictionary) {
  36. return str;
  37. }
  38. var item = this.dictionary[str];
  39. if (!item || !item.textContent) {
  40. return str;
  41. }
  42. return item.textContent;
  43. }
  44. }
  45. }