mirror of
https://github.com/frappe/books.git
synced 2024-12-23 11:29:03 +00:00
feat: setup translations 😎
This commit is contained in:
parent
f1ad28b2cc
commit
ce3d997ed2
@ -91,7 +91,6 @@ module.exports = {
|
||||
this.flags = {};
|
||||
this.methods = {};
|
||||
this.errorLog = [];
|
||||
this.languages = {};
|
||||
// temp params while calling routes
|
||||
this.params = {};
|
||||
},
|
||||
|
@ -1,3 +1,9 @@
|
||||
import {
|
||||
getIndexFormat,
|
||||
getIndexList,
|
||||
getSnippets,
|
||||
getWhitespaceSanitized,
|
||||
} from '../../scripts/helpers';
|
||||
import { ValueError } from '../common/errors';
|
||||
|
||||
class TranslationString {
|
||||
@ -14,19 +20,23 @@ class TranslationString {
|
||||
return this;
|
||||
}
|
||||
|
||||
#translate(segment) {
|
||||
const startSpace = segment.match(/^\s+/)?.[0] ?? '';
|
||||
const endSpace = segment.match(/\s+$/)?.[0] ?? '';
|
||||
segment = segment.replace(/\s+/g, ' ').trim();
|
||||
// TODO: implement translation backend
|
||||
// segment = translate(segment)
|
||||
return startSpace + segment + endSpace;
|
||||
}
|
||||
|
||||
#formatArg(arg) {
|
||||
return arg ?? '';
|
||||
}
|
||||
|
||||
#translate() {
|
||||
let indexFormat = getIndexFormat(this.args[0]);
|
||||
indexFormat = getWhitespaceSanitized(indexFormat);
|
||||
|
||||
const translatedIndexFormat =
|
||||
this.languageMap[indexFormat]?.translation ?? indexFormat;
|
||||
|
||||
this.argList = getIndexList(translatedIndexFormat).map(
|
||||
(i) => this.argList[i]
|
||||
);
|
||||
this.strList = getSnippets(translatedIndexFormat);
|
||||
}
|
||||
|
||||
#stitch() {
|
||||
if (!(this.args[0] instanceof Array)) {
|
||||
throw new ValueError(
|
||||
@ -36,10 +46,15 @@ class TranslationString {
|
||||
);
|
||||
}
|
||||
|
||||
const strList = this.args[0];
|
||||
const argList = this.args.slice(1);
|
||||
return strList
|
||||
.map((s, i) => this.#translate(s) + this.#formatArg(argList[i]))
|
||||
this.strList = this.args[0];
|
||||
this.argList = this.args.slice(1);
|
||||
|
||||
if (this.languageMap) {
|
||||
this.#translate();
|
||||
}
|
||||
|
||||
return this.strList
|
||||
.map((s, i) => s + this.#formatArg(this.argList[i]))
|
||||
.join('')
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
@ -65,3 +80,7 @@ export function T(...args) {
|
||||
export function t(...args) {
|
||||
return new TranslationString(...args).s;
|
||||
}
|
||||
|
||||
export function setLanguageMapOnTranslationString(languageMap) {
|
||||
TranslationString.prototype.languageMap = languageMap;
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ export async function connectToLocalDatabase(filePath) {
|
||||
|
||||
// set file info in config
|
||||
const { companyName } = frappe.AccountingSettings;
|
||||
await setLanguageMap();
|
||||
let files = config.get('files') || [];
|
||||
if (
|
||||
!files.find(
|
||||
@ -90,7 +91,6 @@ export async function connectToLocalDatabase(filePath) {
|
||||
|
||||
// set last selected file
|
||||
config.set('lastSelectedFilePath', filePath);
|
||||
await setLanguageMap();
|
||||
|
||||
// second init with currency, normal usage
|
||||
await callInitializeMoneyMaker();
|
||||
|
@ -4,9 +4,9 @@ import { DEFAULT_LOCALE } from 'frappe/utils/consts';
|
||||
import countryList from '~/fixtures/countryInfo.json';
|
||||
import generateTaxes from '../../../models/doctype/Tax/RegionalEntries';
|
||||
import regionalModelUpdates from '../../../models/regionalModelUpdates';
|
||||
import { callInitializeMoneyMaker } from '../../utils';
|
||||
import { callInitializeMoneyMaker, setLanguageMap } from '../../utils';
|
||||
|
||||
export default async function setupCompany(setupWizardValues) {
|
||||
export default async function setupCompany(setupWizardValues, language) {
|
||||
const {
|
||||
companyLogo,
|
||||
companyName,
|
||||
@ -18,6 +18,7 @@ export default async function setupCompany(setupWizardValues) {
|
||||
fiscalYearEnd,
|
||||
} = setupWizardValues;
|
||||
|
||||
await setLanguageMap(language);
|
||||
const accountingSettings = frappe.AccountingSettings;
|
||||
const currency = countryList[country]['currency'];
|
||||
const locale = countryList[country]['locale'] ?? DEFAULT_LOCALE;
|
||||
@ -45,12 +46,12 @@ export default async function setupCompany(setupWizardValues) {
|
||||
await setupGlobalCurrencies(countryList);
|
||||
await setupChartOfAccounts(bankName, country);
|
||||
await setupRegionalChanges(country);
|
||||
updateCompanyNameInConfig();
|
||||
updateInitializationConfig();
|
||||
|
||||
await accountingSettings.update({ setupComplete: 1 });
|
||||
frappe.AccountingSettings = accountingSettings;
|
||||
|
||||
(await frappe.getSingle('SystemSettings')).update({ locale });
|
||||
(await frappe.getSingle('SystemSettings')).update({ locale, language });
|
||||
}
|
||||
|
||||
async function setupGlobalCurrencies(countries) {
|
||||
@ -109,7 +110,7 @@ async function setupRegionalChanges(country) {
|
||||
await frappe.db.migrate();
|
||||
}
|
||||
|
||||
function updateCompanyNameInConfig() {
|
||||
function updateInitializationConfig(language) {
|
||||
let filePath = frappe.db.dbPath;
|
||||
let files = config.get('files', []);
|
||||
files.forEach((file) => {
|
||||
|
18
src/utils.js
18
src/utils.js
@ -4,11 +4,12 @@ import router from '@/router';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import frappe, { t } from 'frappe';
|
||||
import { isPesa } from 'frappe/utils';
|
||||
import { setLanguageMapOnTranslationString } from 'frappe/utils/translation';
|
||||
import lodash from 'lodash';
|
||||
import { createApp, h } from 'vue';
|
||||
import { handleErrorWithDialog } from './errorHandling';
|
||||
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
|
||||
import { languageCodeMap } from './languageCodeMap';
|
||||
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
|
||||
|
||||
export async function showMessageDialog({
|
||||
message,
|
||||
@ -458,15 +459,14 @@ export function stringifyCircular(
|
||||
|
||||
export async function checkForUpdates(force = false) {
|
||||
ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES, force);
|
||||
await setLanguageMap(getLanguageCode());
|
||||
await setLanguageMap();
|
||||
}
|
||||
|
||||
export async function setLanguageMap(code) {
|
||||
if (code === undefined) {
|
||||
code = getLanguageCode();
|
||||
}
|
||||
export async function setLanguageMap(language) {
|
||||
const code = getLanguageCode(language);
|
||||
|
||||
if (code === 'en') {
|
||||
setLanguageMapOnTranslationString(undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -480,10 +480,10 @@ export async function setLanguageMap(code) {
|
||||
return;
|
||||
}
|
||||
|
||||
frappe.languages[code] = languageMap;
|
||||
setLanguageMapOnTranslationString(languageMap);
|
||||
}
|
||||
|
||||
export function getLanguageCode() {
|
||||
const { language } = frappe.SystemSettings;
|
||||
export function getLanguageCode(initLanguage) {
|
||||
const { language } = initLanguage ?? frappe.SystemSettings;
|
||||
return languageCodeMap[language || 'English'];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user