index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. const Fs = require('fs');
  3. const Event = Editor.require('packages://i18n/utils/event');
  4. const Home = Editor.require('packages://i18n/panel/component/home');
  5. Editor.Panel.extend({
  6. style: Fs.readFileSync(Editor.url('packages://i18n/panel/style/home.css')),
  7. template: Home.template,
  8. $: {},
  9. ready () {
  10. if (!window.Vue) {
  11. // todo 错误信息
  12. return;
  13. }
  14. Home.el = this.shadowRoot;
  15. Home.data = Home.data();
  16. delete Home.props;
  17. delete Home.template;
  18. Home.components = {};
  19. this._vm = new Vue(Home);
  20. window.vm = this._vm
  21. let profile = this.profiles.project;
  22. if (profile.data.languages) {
  23. profile.data.languages.forEach((name) => {
  24. this._vm.languages.push(name)
  25. });
  26. }
  27. let current = profile.data['default_language'];
  28. if (this._vm.languages.indexOf(current) === -1) {
  29. this._vm.current = this._vm.languages[0];
  30. Editor.warn(`Language is not found - ${current}`);
  31. } else {
  32. this._vm.current = current;
  33. }
  34. Event.on('language-changed', (name) => {
  35. profile.data['default_language'] = name;
  36. profile.save();
  37. Editor.Scene.callSceneScript('i18n', 'update-default-language', name, function (err, result) {
  38. // console.log(result);
  39. });
  40. });
  41. Event.on('languages-changed', (languages) => {
  42. profile.data.languages = languages.map((name) => {
  43. return name;
  44. });
  45. profile.save();
  46. })
  47. },
  48. });