2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 19:39:07 +00:00

feat: add a setting for language

This commit is contained in:
18alantom 2022-02-16 17:03:39 +05:30
parent 76d1f3c7f5
commit f1ad28b2cc
7 changed files with 50 additions and 9 deletions

View File

@ -4,7 +4,9 @@ const {
DEFAULT_DISPLAY_PRECISION, DEFAULT_DISPLAY_PRECISION,
DEFAULT_INTERNAL_PRECISION, DEFAULT_INTERNAL_PRECISION,
DEFAULT_LOCALE, DEFAULT_LOCALE,
DEFAULT_LANGUAGE,
} = require('../../../utils/consts'); } = require('../../../utils/consts');
const { languageCodeMap } = require('@/languageCodeMap');
let dateFormatOptions = (() => { let dateFormatOptions = (() => {
let formats = [ let formats = [
@ -51,6 +53,14 @@ module.exports = {
default: DEFAULT_LOCALE, default: DEFAULT_LOCALE,
description: t`Set the local code, this is used for number formatting.`, 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', fieldname: 'displayPrecision',
label: t`Display Precision`, label: t`Display Precision`,
@ -93,8 +103,9 @@ module.exports = {
}, },
], ],
quickEditFields: [ quickEditFields: [
'dateFormat',
'locale', 'locale',
'language',
'dateFormat',
'displayPrecision', 'displayPrecision',
'hideGetStarted', 'hideGetStarted',
'autoReportErrors', 'autoReportErrors',

View File

@ -1,3 +1,4 @@
export const DEFAULT_INTERNAL_PRECISION = 11; export const DEFAULT_INTERNAL_PRECISION = 11;
export const DEFAULT_DISPLAY_PRECISION = 2; export const DEFAULT_DISPLAY_PRECISION = 2;
export const DEFAULT_LOCALE = 'en-IN'; export const DEFAULT_LOCALE = 'en-IN';
export const DEFAULT_LANGUAGE = 'English';

View File

@ -110,7 +110,7 @@ export default {
this.activeScreen = 'SetupWizard'; this.activeScreen = 'SetupWizard';
} else { } else {
this.activeScreen = 'Desk'; this.activeScreen = 'Desk';
checkForUpdates(false); await checkForUpdates(false);
} }
if (!resetRoute) { if (!resetRoute) {

View File

@ -6,7 +6,7 @@ import regionalModelUpdates from '../models/regionalModelUpdates';
import postStart, { setCurrencySymbols } from '../server/postStart'; import postStart, { setCurrencySymbols } from '../server/postStart';
import { DB_CONN_FAILURE } from './messages'; import { DB_CONN_FAILURE } from './messages';
import runMigrate from './migrate'; import runMigrate from './migrate';
import { callInitializeMoneyMaker, getSavePath } from './utils'; import { callInitializeMoneyMaker, getSavePath, setLanguageMap } from './utils';
export async function createNewDatabase() { export async function createNewDatabase() {
const { canceled, filePath } = await getSavePath('books', 'db'); const { canceled, filePath } = await getSavePath('books', 'db');
@ -90,6 +90,7 @@ export async function connectToLocalDatabase(filePath) {
// set last selected file // set last selected file
config.set('lastSelectedFilePath', filePath); config.set('lastSelectedFilePath', filePath);
await setLanguageMap();
// second init with currency, normal usage // second init with currency, normal usage
await callInitializeMoneyMaker(); await callInitializeMoneyMaker();

7
src/languageCodeMap.js Normal file
View File

@ -0,0 +1,7 @@
// Language: Language Code in books/translations
export const languageCodeMap = {
English: 'en',
French: 'fr',
German: 'de',
Portuguese: 'pt',
};

View File

@ -61,7 +61,7 @@ import Icon from '@/components/Icon';
import PageHeader from '@/components/PageHeader'; import PageHeader from '@/components/PageHeader';
import StatusBadge from '@/components/StatusBadge'; import StatusBadge from '@/components/StatusBadge';
import { callInitializeMoneyMaker } from '../../utils'; import { callInitializeMoneyMaker } from '../../utils';
import { showToast } from '../../utils'; import { showToast, setLanguageMap } from '../../utils';
import { h, markRaw } from 'vue'; import { h, markRaw } from 'vue';
export default { export default {
@ -111,11 +111,19 @@ export default {
if ( if (
fieldnames.includes('displayPrecision') || fieldnames.includes('displayPrecision') ||
fieldnames.includes('hideGetStarted') fieldnames.includes('hideGetStarted') ||
fieldnames.includes('language')
) { ) {
callInitializeMoneyMaker(undefined, true);
this.showReloadToast(); this.showReloadToast();
} }
if (fieldnames.includes('displayPrecision')) {
callInitializeMoneyMaker(undefined, true);
}
if (fieldnames.includes('language')) {
setLanguageMap();
}
}, },
methods: { methods: {
showReloadToast() { showReloadToast() {

View File

@ -8,6 +8,7 @@ import lodash from 'lodash';
import { createApp, h } from 'vue'; import { createApp, h } from 'vue';
import { handleErrorWithDialog } from './errorHandling'; import { handleErrorWithDialog } from './errorHandling';
import { IPC_ACTIONS, IPC_MESSAGES } from './messages'; import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
import { languageCodeMap } from './languageCodeMap';
export async function showMessageDialog({ export async function showMessageDialog({
message, message,
@ -455,13 +456,20 @@ export function stringifyCircular(
}); });
} }
window.showToast = showToast; export async function checkForUpdates(force = false) {
export function checkForUpdates(force = false) {
ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES, force); ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES, force);
await setLanguageMap(getLanguageCode());
} }
export async function setLanguageMap(code) { export async function setLanguageMap(code) {
if (code === undefined) {
code = getLanguageCode();
}
if (code === 'en') {
return;
}
const { success, message, languageMap } = await ipcRenderer.invoke( const { success, message, languageMap } = await ipcRenderer.invoke(
IPC_ACTIONS.GET_LANGUAGE_MAP, IPC_ACTIONS.GET_LANGUAGE_MAP,
code code
@ -474,3 +482,8 @@ export async function setLanguageMap(code) {
frappe.languages[code] = languageMap; frappe.languages[code] = languageMap;
} }
export function getLanguageCode() {
const { language } = frappe.SystemSettings;
return languageCodeMap[language || 'English'];
}