mirror of
https://github.com/frappe/books.git
synced 2024-12-23 03:19:01 +00:00
feat: add a setting for language
This commit is contained in:
parent
76d1f3c7f5
commit
f1ad28b2cc
@ -4,7 +4,9 @@ const {
|
||||
DEFAULT_DISPLAY_PRECISION,
|
||||
DEFAULT_INTERNAL_PRECISION,
|
||||
DEFAULT_LOCALE,
|
||||
DEFAULT_LANGUAGE,
|
||||
} = require('../../../utils/consts');
|
||||
const { languageCodeMap } = require('@/languageCodeMap');
|
||||
|
||||
let dateFormatOptions = (() => {
|
||||
let formats = [
|
||||
@ -51,6 +53,14 @@ module.exports = {
|
||||
default: DEFAULT_LOCALE,
|
||||
description: t`Set the local code, this is used for number formatting.`,
|
||||
},
|
||||
{
|
||||
fieldname: 'language',
|
||||
label: t`Language`,
|
||||
fieldtype: 'Select',
|
||||
options: Object.keys(languageCodeMap),
|
||||
default: DEFAULT_LANGUAGE,
|
||||
description: t`Set the display language.`,
|
||||
},
|
||||
{
|
||||
fieldname: 'displayPrecision',
|
||||
label: t`Display Precision`,
|
||||
@ -93,8 +103,9 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
quickEditFields: [
|
||||
'dateFormat',
|
||||
'locale',
|
||||
'language',
|
||||
'dateFormat',
|
||||
'displayPrecision',
|
||||
'hideGetStarted',
|
||||
'autoReportErrors',
|
||||
|
@ -1,3 +1,4 @@
|
||||
export const DEFAULT_INTERNAL_PRECISION = 11;
|
||||
export const DEFAULT_DISPLAY_PRECISION = 2;
|
||||
export const DEFAULT_LOCALE = 'en-IN';
|
||||
export const DEFAULT_LANGUAGE = 'English';
|
@ -110,7 +110,7 @@ export default {
|
||||
this.activeScreen = 'SetupWizard';
|
||||
} else {
|
||||
this.activeScreen = 'Desk';
|
||||
checkForUpdates(false);
|
||||
await checkForUpdates(false);
|
||||
}
|
||||
|
||||
if (!resetRoute) {
|
||||
|
@ -6,7 +6,7 @@ import regionalModelUpdates from '../models/regionalModelUpdates';
|
||||
import postStart, { setCurrencySymbols } from '../server/postStart';
|
||||
import { DB_CONN_FAILURE } from './messages';
|
||||
import runMigrate from './migrate';
|
||||
import { callInitializeMoneyMaker, getSavePath } from './utils';
|
||||
import { callInitializeMoneyMaker, getSavePath, setLanguageMap } from './utils';
|
||||
|
||||
export async function createNewDatabase() {
|
||||
const { canceled, filePath } = await getSavePath('books', 'db');
|
||||
@ -90,6 +90,7 @@ export async function connectToLocalDatabase(filePath) {
|
||||
|
||||
// set last selected file
|
||||
config.set('lastSelectedFilePath', filePath);
|
||||
await setLanguageMap();
|
||||
|
||||
// second init with currency, normal usage
|
||||
await callInitializeMoneyMaker();
|
||||
|
7
src/languageCodeMap.js
Normal file
7
src/languageCodeMap.js
Normal file
@ -0,0 +1,7 @@
|
||||
// Language: Language Code in books/translations
|
||||
export const languageCodeMap = {
|
||||
English: 'en',
|
||||
French: 'fr',
|
||||
German: 'de',
|
||||
Portuguese: 'pt',
|
||||
};
|
@ -61,7 +61,7 @@ import Icon from '@/components/Icon';
|
||||
import PageHeader from '@/components/PageHeader';
|
||||
import StatusBadge from '@/components/StatusBadge';
|
||||
import { callInitializeMoneyMaker } from '../../utils';
|
||||
import { showToast } from '../../utils';
|
||||
import { showToast, setLanguageMap } from '../../utils';
|
||||
import { h, markRaw } from 'vue';
|
||||
|
||||
export default {
|
||||
@ -111,11 +111,19 @@ export default {
|
||||
|
||||
if (
|
||||
fieldnames.includes('displayPrecision') ||
|
||||
fieldnames.includes('hideGetStarted')
|
||||
fieldnames.includes('hideGetStarted') ||
|
||||
fieldnames.includes('language')
|
||||
) {
|
||||
callInitializeMoneyMaker(undefined, true);
|
||||
this.showReloadToast();
|
||||
}
|
||||
|
||||
if (fieldnames.includes('displayPrecision')) {
|
||||
callInitializeMoneyMaker(undefined, true);
|
||||
}
|
||||
|
||||
if (fieldnames.includes('language')) {
|
||||
setLanguageMap();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
showReloadToast() {
|
||||
|
19
src/utils.js
19
src/utils.js
@ -8,6 +8,7 @@ import lodash from 'lodash';
|
||||
import { createApp, h } from 'vue';
|
||||
import { handleErrorWithDialog } from './errorHandling';
|
||||
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
|
||||
import { languageCodeMap } from './languageCodeMap';
|
||||
|
||||
export async function showMessageDialog({
|
||||
message,
|
||||
@ -455,13 +456,20 @@ export function stringifyCircular(
|
||||
});
|
||||
}
|
||||
|
||||
window.showToast = showToast;
|
||||
|
||||
export function checkForUpdates(force = false) {
|
||||
export async function checkForUpdates(force = false) {
|
||||
ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES, force);
|
||||
await setLanguageMap(getLanguageCode());
|
||||
}
|
||||
|
||||
export async function setLanguageMap(code) {
|
||||
if (code === undefined) {
|
||||
code = getLanguageCode();
|
||||
}
|
||||
|
||||
if (code === 'en') {
|
||||
return;
|
||||
}
|
||||
|
||||
const { success, message, languageMap } = await ipcRenderer.invoke(
|
||||
IPC_ACTIONS.GET_LANGUAGE_MAP,
|
||||
code
|
||||
@ -474,3 +482,8 @@ export async function setLanguageMap(code) {
|
||||
|
||||
frappe.languages[code] = languageMap;
|
||||
}
|
||||
|
||||
export function getLanguageCode() {
|
||||
const { language } = frappe.SystemSettings;
|
||||
return languageCodeMap[language || 'English'];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user