Skip to content

Commit

Permalink
Merge pull request #2901 from ONLYOFFICE/feature/optimize-translation…
Browse files Browse the repository at this point in the history
…s-loading

Feature/optimize translations loading
  • Loading branch information
maxkadushkin authored Apr 4, 2024
2 parents 7bc29d2 + 872ae73 commit 2044982
Show file tree
Hide file tree
Showing 44 changed files with 3,435 additions and 205 deletions.
15 changes: 15 additions & 0 deletions apps/common/mobile/utils/processArrayScripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const processArrayScripts = async (array, fn) => {
const results = [];

for (const item of array) {
try {
const data = await fn(item);
results.push(data);
} catch (error) {
console.log(`Error with processing element ${item}:`, error);
continue;
}
}

return results;
};
27 changes: 3 additions & 24 deletions apps/documenteditor/mobile/src/controller/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PluginsController from '../../../../common/mobile/lib/controller/Plugins.
import EncodingController from "./Encoding";
import DropdownListController from "./DropdownList";
import { Device } from '../../../../common/mobile/utils/device';
import { processArrayScripts } from '../../../../common/mobile/utils/processArrayScripts.js';

@inject(
"users",
Expand Down Expand Up @@ -385,35 +386,13 @@ class MainController extends Component {
}
};

const _process_array = async (array, fn) => {
const results = [];

for (const item of array) {
try {
const data = await fn(item);
results.push(data);
} catch (error) {
console.log(`Error with processing element ${item}:`, error);
continue;
}
}

return results;
};

_process_array(dep_scripts, promise_get_script)
processArrayScripts(dep_scripts, promise_get_script)
.then(() => {
window["flat_desine"] = true;
const { t } = this.props;
let _translate = t('Main.SDK', { returnObjects: true });

if (typeof _translate === 'object') {
Object.entries(_translate).forEach(([key, value]) => {
if (key.endsWith(' ') && !value.endsWith(' ')) {
_translate[key] = value + ' ';
}
});
} else {
if (!(typeof _translate === 'object' && _translate !== null && Object.keys(_translate).length > 0)) {
_translate = this.fallbackSdkTranslations
}

Expand Down
52 changes: 36 additions & 16 deletions apps/presentationeditor/mobile/src/controller/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import About from '../../../../common/mobile/lib/view/About';
import PluginsController from '../../../../common/mobile/lib/controller/Plugins.jsx';
import { Device } from '../../../../common/mobile/utils/device';
import { Themes } from '../../../../common/mobile/lib/controller/Themes.jsx';
import { processArrayScripts } from '../../../../common/mobile/utils/processArrayScripts.js';

@inject(
"users",
Expand All @@ -38,6 +39,31 @@ class MainController extends Component {

this.LoadingDocument = -256;
this.ApplyEditRights = -255;
this.fallbackSdkTranslations = {
"Chart": "Chart",
"Click to add first slide": "Click to add first slide",
"Click to add notes": "Click to add notes",
"ClipArt": "Clip Art",
"Date and time": "Date and time",
"Diagram": "Diagram",
"Diagram Title": "Chart Title",
"Footer": "Footer",
"Header": "Header",
"Image": "Image",
"Loading": "Loading",
"Media": "Media",
"None": "None",
"Picture": "Picture",
"Series": "Series",
"Slide number": "Slide number",
"Slide subtitle": "Slide subtitle",
"Slide text": "Slide text",
"Slide title": "Slide title",
"Table": "Table",
"X Axis": "X Axis XAS",
"Y Axis": "Y Axis",
"Your text here": "Your text here"
}

this._state = {
licenseType: false,
Expand Down Expand Up @@ -191,30 +217,24 @@ class MainController extends Component {
this.api.Resize();
};

const _process_array = (array, fn) => {
let results = [];
return array.reduce(function(p, item) {
return p.then(function() {
return fn(item).then(function(data) {
results.push(data);
return results;
});
});
}, Promise.resolve());
};
processArrayScripts(dep_scripts, promise_get_script)
.then(() => {
const { t } = this.props;
let _translate = t('Controller.Main.SDK', { returnObjects:true })

if (!(typeof _translate === 'object' && _translate !== null && Object.keys(_translate).length > 0)) {
_translate = this.fallbackSdkTranslations
}

_process_array(dep_scripts, promise_get_script)
.then ( result => {
const {t} = this.props;
this.api = new Asc.asc_docs_api({
'id-view': 'editor_sdk',
'mobile': true,
'translate': t('Controller.Main.SDK', {returnObjects:true})
'translate': _translate
});

Common.Notifications.trigger('engineCreated', this.api);

this.appOptions = {};
this.appOptions = {};
this.bindEvents();

let value = LocalStorage.getItem("pe-settings-fontrender");
Expand Down
9 changes: 9 additions & 0 deletions apps/presentationeditor/mobile/src/lib/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ i18n.use(initReactI18next)
react: {
useSuspense: false,
},
}).then(() => {
console.log("i18next is ready");
})
.catch((error) => {
console.error("i18next initialization error:", error);
});

i18n.on('failedLoading', (lng, ns, msg) => {
console.log(msg);
});

export default i18n;
87 changes: 86 additions & 1 deletion apps/spreadsheeteditor/mobile/locale/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,92 @@
"txtValues": "القيم",
"txtXAxis": "محور السينات",
"txtYAxis": "محور الصادات",
"txtYears": "السنوات"
"txtYears": "السنوات",
"Accent": "Accent",
"Accent1": "Accent1",
"Accent2": "Accent2",
"Accent3": "Accent3",
"Accent4": "Accent4",
"Accent5": "Accent5",
"Accent6": "Accent6",
"20% - Accent1": "20% - Accent1",
"20% - Accent2": "20% - Accent2",
"20% - Accent3": "20% - Accent3",
"20% - Accent4": "20% - Accent4",
"20% - Accent5": "20% - Accent5",
"20% - Accent6": "20% - Accent6",
"40% - Accent1": "40% - Accent1",
"40% - Accent2": "40% - Accent2",
"40% - Accent3": "40% - Accent3",
"40% - Accent4": "40% - Accent4",
"40% - Accent5": "40% - Accent5",
"40% - Accent6": "40% - Accent6",
"60% - Accent1": "60% - Accent1",
"60% - Accent2": "60% - Accent2",
"60% - Accent3": "60% - Accent3",
"60% - Accent4": "60% - Accent4",
"60% - Accent5": "60% - Accent5",
"60% - Accent6": "60% - Accent6",
"(All)": "(All)",
"Your text here": "Your text here",
"(blank)": "(blank)",
"%1 of %2": "%1 of %2",
"Clear Filter (Alt+C)": "Clear Filter (Alt+C)",
"Column Labels": "Column Labels",
"Column": "Column",
"Confidential": "Confidential",
"Date": "Date",
"Days": "Days",
"Diagram Title": "Chart Title",
"File": "File",
"Grand Total": "Grand Total",
"Group": "Group",
"Hours": "Hours",
"Minutes": "Minutes",
"Months": "Months",
"Multi-Select (Alt+S)": "Multi-Select (Alt+S)",
"%1 or %2": "%1 or %2",
"Page": "Page",
"Page %1 of %2": "Page %1 of %2",
"Pages": "Pages",
"Prepared by": "Prepared by",
"Print_Area": "Print_Area",
"Qtr": "Qtr",
"Quarters": "Quarters",
"Row": "Row",
"Row Labels": "Row Labels",
"Seconds": "Seconds",
"Series": "Series",
"Bad": "Bad",
"Calculation": "Calculation",
"Check Cell": "Check Cell",
"Comma": "Comma",
"Comma [0]": "Comma [0]",
"Currency": "Currency",
"Currency [0]": "Currency [0]",
"Explanatory Text": "Explanatory Text",
"Good": "Good",
"Heading 1": "Heading 1",
"Heading 2": "Heading 2",
"Heading 3": "Heading 3",
"Heading 4": "Heading 4",
"Input": "Input",
"Linked Cell": "Linked Cell",
"Neutral": "Neutral",
"Normal": "Normal",
"Note": "Note",
"Output": "Output",
"Percent": "Percent",
"Title": "Title",
"Total": "Total",
"Warning Text": "Warning Text",
"Tab": "Tab",
"Table": "Table",
"Time": "Time",
"Values": "Values",
"X Axis": "X Axis",
"Y Axis": "Y Axis",
"Years": "Years"
},
"textAnonymous": "مجهول",
"textBuyNow": "زيارة الموقع",
Expand Down
87 changes: 86 additions & 1 deletion apps/spreadsheeteditor/mobile/locale/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,92 @@
"txtValues": "Dəyərlər",
"txtXAxis": "X Oxu",
"txtYAxis": "Y Oxu",
"txtYears": "İllər"
"txtYears": "İllər",
"Accent": "Accent",
"Accent1": "Accent1",
"Accent2": "Accent2",
"Accent3": "Accent3",
"Accent4": "Accent4",
"Accent5": "Accent5",
"Accent6": "Accent6",
"20% - Accent1": "20% - Accent1",
"20% - Accent2": "20% - Accent2",
"20% - Accent3": "20% - Accent3",
"20% - Accent4": "20% - Accent4",
"20% - Accent5": "20% - Accent5",
"20% - Accent6": "20% - Accent6",
"40% - Accent1": "40% - Accent1",
"40% - Accent2": "40% - Accent2",
"40% - Accent3": "40% - Accent3",
"40% - Accent4": "40% - Accent4",
"40% - Accent5": "40% - Accent5",
"40% - Accent6": "40% - Accent6",
"60% - Accent1": "60% - Accent1",
"60% - Accent2": "60% - Accent2",
"60% - Accent3": "60% - Accent3",
"60% - Accent4": "60% - Accent4",
"60% - Accent5": "60% - Accent5",
"60% - Accent6": "60% - Accent6",
"(All)": "(All)",
"Your text here": "Your text here",
"(blank)": "(blank)",
"%1 of %2": "%1 of %2",
"Clear Filter (Alt+C)": "Clear Filter (Alt+C)",
"Column Labels": "Column Labels",
"Column": "Column",
"Confidential": "Confidential",
"Date": "Date",
"Days": "Days",
"Diagram Title": "Chart Title",
"File": "File",
"Grand Total": "Grand Total",
"Group": "Group",
"Hours": "Hours",
"Minutes": "Minutes",
"Months": "Months",
"Multi-Select (Alt+S)": "Multi-Select (Alt+S)",
"%1 or %2": "%1 or %2",
"Page": "Page",
"Page %1 of %2": "Page %1 of %2",
"Pages": "Pages",
"Prepared by": "Prepared by",
"Print_Area": "Print_Area",
"Qtr": "Qtr",
"Quarters": "Quarters",
"Row": "Row",
"Row Labels": "Row Labels",
"Seconds": "Seconds",
"Series": "Series",
"Bad": "Bad",
"Calculation": "Calculation",
"Check Cell": "Check Cell",
"Comma": "Comma",
"Comma [0]": "Comma [0]",
"Currency": "Currency",
"Currency [0]": "Currency [0]",
"Explanatory Text": "Explanatory Text",
"Good": "Good",
"Heading 1": "Heading 1",
"Heading 2": "Heading 2",
"Heading 3": "Heading 3",
"Heading 4": "Heading 4",
"Input": "Input",
"Linked Cell": "Linked Cell",
"Neutral": "Neutral",
"Normal": "Normal",
"Note": "Note",
"Output": "Output",
"Percent": "Percent",
"Title": "Title",
"Total": "Total",
"Warning Text": "Warning Text",
"Tab": "Tab",
"Table": "Table",
"Time": "Time",
"Values": "Values",
"X Axis": "X Axis",
"Y Axis": "Y Axis",
"Years": "Years"
},
"textAnonymous": "Anonim",
"textBuyNow": "Veb sayta daxil olun",
Expand Down
Loading

0 comments on commit 2044982

Please sign in to comment.