diff --git a/accounting/gst.js b/accounting/gst.js index c3f8f9d0..8f9687e9 100644 --- a/accounting/gst.js +++ b/accounting/gst.js @@ -1,6 +1,6 @@ import { showMessageDialog } from '@/utils'; import frappe from 'frappe'; -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; import { DateTime } from 'luxon'; import { exportCsv, saveExportData } from '../reports/commonExporter'; import { getSavePath } from '../src/utils'; @@ -89,8 +89,8 @@ export async function generateGstr1Json(getReportData) { const { gstin } = frappe.AccountingSettings; if (!gstin) { showMessageDialog({ - message: _('Export Failed'), - description: _('Please set GSTIN in General Settings.'), + message: t('Export Failed'), + description: t('Please set GSTIN in General Settings.'), }); return; } @@ -269,8 +269,8 @@ export async function generateGstr2Csv(getReportData) { const { gstin } = frappe.AccountingSettings; if (!gstin) { showMessageDialog({ - message: _('Export Failed'), - description: _('Please set GSTIN in General Settings.'), + message: t('Export Failed'), + description: t('Please set GSTIN in General Settings.'), }); return; } @@ -350,8 +350,8 @@ export async function generateGstr1Csv(getReportData) { const { gstin } = frappe.AccountingSettings; if (!gstin) { showMessageDialog({ - message: _('Export Failed'), - description: _('Please set GSTIN in General Settings.'), + message: t('Export Failed'), + description: t('Please set GSTIN in General Settings.'), }); return; } diff --git a/fixtures/standardCOA.js b/fixtures/standardCOA.js index f793474d..35441735 100644 --- a/fixtures/standardCOA.js +++ b/fixtures/standardCOA.js @@ -1,171 +1,170 @@ -import frappe from 'frappe'; -const _ = frappe._.bind(frappe); +import { t } from 'frappe'; export default { - [_('Application of Funds (Assets)')]: { - [_('Current Assets')]: { - [_('Accounts Receivable')]: { - [_('Debtors')]: { + [t('Application of Funds (Assets)')]: { + [t('Current Assets')]: { + [t('Accounts Receivable')]: { + [t('Debtors')]: { accountType: 'Receivable', }, }, - [_('Bank Accounts')]: { + [t('Bank Accounts')]: { accountType: 'Bank', isGroup: 1, }, - [_('Cash In Hand')]: { - [_('Cash')]: { + [t('Cash In Hand')]: { + [t('Cash')]: { accountType: 'Cash', }, accountType: 'Cash', }, - [_('Loans and Advances (Assets)')]: { + [t('Loans and Advances (Assets)')]: { isGroup: 1, }, - [_('Securities and Deposits')]: { - [_('Earnest Money')]: {}, + [t('Securities and Deposits')]: { + [t('Earnest Money')]: {}, }, - [_('Stock Assets')]: { - [_('Stock In Hand')]: { + [t('Stock Assets')]: { + [t('Stock In Hand')]: { accountType: 'Stock', }, accountType: 'Stock', }, - [_('Tax Assets')]: { + [t('Tax Assets')]: { isGroup: 1, }, }, - [_('Fixed Assets')]: { - [_('Capital Equipments')]: { + [t('Fixed Assets')]: { + [t('Capital Equipments')]: { accountType: 'Fixed Asset', }, - [_('Electronic Equipments')]: { + [t('Electronic Equipments')]: { accountType: 'Fixed Asset', }, - [_('Furnitures and Fixtures')]: { + [t('Furnitures and Fixtures')]: { accountType: 'Fixed Asset', }, - [_('Office Equipments')]: { + [t('Office Equipments')]: { accountType: 'Fixed Asset', }, - [_('Plants and Machineries')]: { + [t('Plants and Machineries')]: { accountType: 'Fixed Asset', }, - [_('Buildings')]: { + [t('Buildings')]: { accountType: 'Fixed Asset', }, - [_('Softwares')]: { + [t('Softwares')]: { accountType: 'Fixed Asset', }, - [_('Accumulated Depreciation')]: { + [t('Accumulated Depreciation')]: { accountType: 'Accumulated Depreciation', }, }, - [_('Investments')]: { + [t('Investments')]: { isGroup: 1, }, - [_('Temporary Accounts')]: { - [_('Temporary Opening')]: { + [t('Temporary Accounts')]: { + [t('Temporary Opening')]: { accountType: 'Temporary', }, }, rootType: 'Asset', }, - [_('Expenses')]: { - [_('Direct Expenses')]: { - [_('Stock Expenses')]: { - [_('Cost of Goods Sold')]: { + [t('Expenses')]: { + [t('Direct Expenses')]: { + [t('Stock Expenses')]: { + [t('Cost of Goods Sold')]: { accountType: 'Cost of Goods Sold', }, - [_('Expenses Included In Valuation')]: { + [t('Expenses Included In Valuation')]: { accountType: 'Expenses Included In Valuation', }, - [_('Stock Adjustment')]: { + [t('Stock Adjustment')]: { accountType: 'Stock Adjustment', }, }, }, - [_('Indirect Expenses')]: { - [_('Administrative Expenses')]: {}, - [_('Commission on Sales')]: {}, - [_('Depreciation')]: { + [t('Indirect Expenses')]: { + [t('Administrative Expenses')]: {}, + [t('Commission on Sales')]: {}, + [t('Depreciation')]: { accountType: 'Depreciation', }, - [_('Entertainment Expenses')]: {}, - [_('Freight and Forwarding Charges')]: { + [t('Entertainment Expenses')]: {}, + [t('Freight and Forwarding Charges')]: { accountType: 'Chargeable', }, - [_('Legal Expenses')]: {}, - [_('Marketing Expenses')]: { + [t('Legal Expenses')]: {}, + [t('Marketing Expenses')]: { accountType: 'Chargeable', }, - [_('Miscellaneous Expenses')]: { + [t('Miscellaneous Expenses')]: { accountType: 'Chargeable', }, - [_('Office Maintenance Expenses')]: {}, - [_('Office Rent')]: {}, - [_('Postal Expenses')]: {}, - [_('Print and Stationery')]: {}, - [_('Round Off')]: { + [t('Office Maintenance Expenses')]: {}, + [t('Office Rent')]: {}, + [t('Postal Expenses')]: {}, + [t('Print and Stationery')]: {}, + [t('Round Off')]: { accountType: 'Round Off', }, - [_('Salary')]: {}, - [_('Sales Expenses')]: {}, - [_('Telephone Expenses')]: {}, - [_('Travel Expenses')]: {}, - [_('Utility Expenses')]: {}, - [_('Write Off')]: {}, - [_('Exchange Gain/Loss')]: {}, - [_('Gain/Loss on Asset Disposal')]: {}, + [t('Salary')]: {}, + [t('Sales Expenses')]: {}, + [t('Telephone Expenses')]: {}, + [t('Travel Expenses')]: {}, + [t('Utility Expenses')]: {}, + [t('Write Off')]: {}, + [t('Exchange Gain/Loss')]: {}, + [t('Gain/Loss on Asset Disposal')]: {}, }, rootType: 'Expense', }, - [_('Income')]: { - [_('Direct Income')]: { - [_('Sales')]: {}, - [_('Service')]: {}, + [t('Income')]: { + [t('Direct Income')]: { + [t('Sales')]: {}, + [t('Service')]: {}, }, - [_('Indirect Income')]: { + [t('Indirect Income')]: { isGroup: 1, }, rootType: 'Income', }, - [_('Source of Funds (Liabilities)')]: { - [_('Current Liabilities')]: { - [_('Accounts Payable')]: { - [_('Creditors')]: { + [t('Source of Funds (Liabilities)')]: { + [t('Current Liabilities')]: { + [t('Accounts Payable')]: { + [t('Creditors')]: { accountType: 'Payable', }, - [_('Payroll Payable')]: {}, + [t('Payroll Payable')]: {}, }, - [_('Stock Liabilities')]: { - [_('Stock Received But Not Billed')]: { + [t('Stock Liabilities')]: { + [t('Stock Received But Not Billed')]: { accountType: 'Stock Received But Not Billed', }, }, - [_('Duties and Taxes')]: { + [t('Duties and Taxes')]: { accountType: 'Tax', isGroup: 1, }, - [_('Loans (Liabilities)')]: { - [_('Secured Loans')]: {}, - [_('Unsecured Loans')]: {}, - [_('Bank Overdraft Account')]: {}, + [t('Loans (Liabilities)')]: { + [t('Secured Loans')]: {}, + [t('Unsecured Loans')]: {}, + [t('Bank Overdraft Account')]: {}, }, }, rootType: 'Liability', }, - [_('Equity')]: { - [_('Capital Stock')]: { + [t('Equity')]: { + [t('Capital Stock')]: { accountType: 'Equity', }, - [_('Dividends Paid')]: { + [t('Dividends Paid')]: { accountType: 'Equity', }, - [_('Opening Balance Equity')]: { + [t('Opening Balance Equity')]: { accountType: 'Equity', }, - [_('Retained Earnings')]: { + [t('Retained Earnings')]: { accountType: 'Equity', }, rootType: 'Equity', diff --git a/frappe/index.js b/frappe/index.js index 363a2c55..f9a0c676 100644 --- a/frappe/index.js +++ b/frappe/index.js @@ -1,4 +1,5 @@ const Observable = require('./utils/observable'); +const { T, t } = require('./utils/translation'); const utils = require('./utils'); const { getMoneyMaker } = require('pesa'); const { @@ -227,8 +228,10 @@ module.exports = { return this.metaCache[doctype]; }, - async getDoc(doctype, name, options = {skipDocumentCache: false}) { - let doc = options.skipDocumentCache ? null : this.getDocFromCache(doctype, name); + async getDoc(doctype, name, options = { skipDocumentCache: false }) { + let doc = options.skipDocumentCache + ? null + : this.getDocFromCache(doctype, name); if (!doc) { doc = new (this.getDocumentClass(doctype))({ doctype: doctype, @@ -369,4 +372,6 @@ module.exports = { this.server.close(); } }, + t, + T, }; diff --git a/frappe/model/document.js b/frappe/model/document.js index bdf2f7e9..3552cf7d 100644 --- a/frappe/model/document.js +++ b/frappe/model/document.js @@ -211,7 +211,7 @@ module.exports = class BaseDocument extends Observable { if (missingMandatory.length > 0) { let fields = missingMandatory.join('\n'); - let message = frappe._('Value missing for {0}', fields); + let message = frappe.t('Value missing for {0}', fields); throw new frappe.errors.MandatoryError(message); } @@ -409,7 +409,7 @@ module.exports = class BaseDocument extends Observable { // check for conflict if (currentDoc && this.modified != currentDoc.modified) { throw new frappe.errors.Conflict( - frappe._('Document {0} {1} has been modified after loading', [ + frappe.t('Document {0} {1} has been modified after loading', [ this.doctype, this.name, ]) @@ -418,7 +418,7 @@ module.exports = class BaseDocument extends Observable { if (this.submitted && !this.meta.isSubmittable) { throw new frappe.errors.ValidationError( - frappe._('Document type {1} is not submittable', [this.doctype]) + frappe.t('Document type {1} is not submittable', [this.doctype]) ); } diff --git a/frappe/model/meta.js b/frappe/model/meta.js index f8a7b567..47cafc10 100644 --- a/frappe/model/meta.js +++ b/frappe/model/meta.js @@ -33,7 +33,7 @@ module.exports = class BaseMeta extends BaseDocument { if (!this.fields.find(df => df.fieldname === 'name') && !this.isSingle) { this.fields = [ { - label: frappe._('ID'), + label: frappe.t('ID'), fieldname: 'name', fieldtype: 'Data', required: 1, @@ -176,7 +176,7 @@ module.exports = class BaseMeta extends BaseDocument { _add({ fieldtype: 'Check', fieldname: 'submitted', - label: frappe._('Submitted') + label: frappe.t('Submitted') }); } diff --git a/frappe/models/doctype/SystemSettings/SystemSettings.js b/frappe/models/doctype/SystemSettings/SystemSettings.js index fc011f4f..e785f1f6 100644 --- a/frappe/models/doctype/SystemSettings/SystemSettings.js +++ b/frappe/models/doctype/SystemSettings/SystemSettings.js @@ -1,5 +1,5 @@ const { DateTime } = require('luxon'); -const { _ } = require('frappe/utils'); +const { t } = require('frappe'); const { DEFAULT_DISPLAY_PRECISION, DEFAULT_INTERNAL_PRECISION, @@ -42,14 +42,14 @@ module.exports = { options: dateFormatOptions, default: 'MMM d, y', required: 1, - description: _('Sets the app-wide date display format.'), + description: t('Sets the app-wide date display format.'), }, { fieldname: 'locale', label: 'Locale', fieldtype: 'Data', default: DEFAULT_LOCALE, - description: _('Set the local code, this is used for number formatting.'), + description: t('Set the local code, this is used for number formatting.'), }, { fieldname: 'displayPrecision', @@ -64,10 +64,10 @@ module.exports = { return; } throw new frappe.errors.ValidationError( - _('Display Precision should have a value between 0 and 9.') + t('Display Precision should have a value between 0 and 9.') ); }, - description: _('Sets how many digits are shown after the decimal point.'), + description: t('Sets how many digits are shown after the decimal point.'), }, { fieldname: 'internalPrecision', @@ -75,7 +75,7 @@ module.exports = { fieldtype: 'Int', minValue: 0, default: DEFAULT_INTERNAL_PRECISION, - description: _( + description: t( 'Sets the internal precision used for monetary calculations. Above 6 should be sufficient for most currencies.' ), }, @@ -84,7 +84,7 @@ module.exports = { label: 'Hide Get Started', fieldtype: 'Check', default: 0, - description: _( + description: t( 'Hides the Get Started section from the sidebar. Change will be visible on restart or refreshing the app.' ), }, @@ -93,7 +93,7 @@ module.exports = { label: 'Auto Update', fieldtype: 'Check', default: 1, - description: _( + description: t( 'Automatically checks for updates and download them if available. The update will be applied after you restart the app.' ), }, @@ -102,7 +102,7 @@ module.exports = { label: 'Auto Report Errors', fieldtype: 'Check', default: 0, - description: _( + description: t( 'Automatically report all errors. User will still be notified when an error pops up.' ), }, diff --git a/frappe/utils/index.js b/frappe/utils/index.js index d7573af0..0abdacf7 100644 --- a/frappe/utils/index.js +++ b/frappe/utils/index.js @@ -1,5 +1,4 @@ const { pesa } = require('pesa'); -const { T, t } = require('./translation'); Array.prototype.equals = function (array) { return ( @@ -88,9 +87,6 @@ function isPesa(value) { } module.exports = { - _: t, - t, - T, slug, getRandomString, sleep, diff --git a/models/doctype/Account/AccountList.js b/models/doctype/Account/AccountList.js index b4fc80d6..feb04c18 100644 --- a/models/doctype/Account/AccountList.js +++ b/models/doctype/Account/AccountList.js @@ -1,7 +1,7 @@ -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; export default { doctype: 'Account', - title: _('Account'), + title: t('Account'), columns: ['name', 'parentAccount', 'rootType'], }; diff --git a/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js b/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js index 5903eb52..9dcab704 100644 --- a/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js +++ b/models/doctype/AccountingLedgerEntry/AccountingLedgerEntryList.js @@ -1,7 +1,7 @@ -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; export default { doctype: 'AccountingLedgerEntry', - title: _('Accounting Ledger Entries'), + title: t('Accounting Ledger Entries'), columns: ['account', 'party', 'debit', 'credit', 'balance'], }; diff --git a/models/doctype/GSTR3B/GSTR3BList.js b/models/doctype/GSTR3B/GSTR3BList.js index f9ca5810..26f08a01 100644 --- a/models/doctype/GSTR3B/GSTR3BList.js +++ b/models/doctype/GSTR3B/GSTR3BList.js @@ -1,7 +1,7 @@ -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; export default { doctype: 'GSTR3B', - title: _('GSTR 3B Report'), + title: t('GSTR 3B Report'), columns: ['year', 'month'], }; diff --git a/models/doctype/GSTR3B/GSTR3BPrintView.vue b/models/doctype/GSTR3B/GSTR3BPrintView.vue index eed1bc93..668c00ad 100644 --- a/models/doctype/GSTR3B/GSTR3BPrintView.vue +++ b/models/doctype/GSTR3B/GSTR3BPrintView.vue @@ -2,7 +2,7 @@
- {{ _('PDF') }} + {{ t('PDF') }}
diff --git a/models/doctype/Item/Item.js b/models/doctype/Item/Item.js index abeb4145..cea0e8a8 100644 --- a/models/doctype/Item/Item.js +++ b/models/doctype/Item/Item.js @@ -1,5 +1,5 @@ import frappe from 'frappe'; -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; export default { name: 'Item', @@ -124,7 +124,7 @@ export default { ], actions: [ { - label: _('New Invoice'), + label: t('New Invoice'), condition: (doc) => !doc.isNew(), action: async (doc, router) => { const invoice = await frappe.getNewDoc('SalesInvoice'); @@ -137,7 +137,7 @@ export default { }, }, { - label: _('New Bill'), + label: t('New Bill'), condition: (doc) => !doc.isNew(), action: async (doc, router) => { const invoice = await frappe.getNewDoc('PurchaseInvoice'); diff --git a/models/doctype/Item/ItemList.js b/models/doctype/Item/ItemList.js index b48bde6f..dac63fbc 100644 --- a/models/doctype/Item/ItemList.js +++ b/models/doctype/Item/ItemList.js @@ -1,7 +1,7 @@ -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; export default { doctype: 'Item', - title: _('Items'), + title: t('Items'), columns: ['name', 'unit', 'tax', 'rate'], }; diff --git a/models/doctype/JournalEntry/JournalEntryList.js b/models/doctype/JournalEntry/JournalEntryList.js index abe57328..bfdc757e 100644 --- a/models/doctype/JournalEntry/JournalEntryList.js +++ b/models/doctype/JournalEntry/JournalEntryList.js @@ -1,9 +1,9 @@ import Badge from '@/components/Badge'; -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; export default { doctype: 'JournalEntry', - title: _('Journal Entry'), + title: t('Journal Entry'), formRoute: (name) => `/edit/JournalEntry/${name}`, columns: [ 'date', diff --git a/models/doctype/Party/Customer.js b/models/doctype/Party/Customer.js index 897b84ef..c2877169 100644 --- a/models/doctype/Party/Customer.js +++ b/models/doctype/Party/Customer.js @@ -1,6 +1,6 @@ import router from '@/router'; import frappe from 'frappe'; -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; import PartyWidget from './PartyWidget.vue'; export default { @@ -12,7 +12,7 @@ export default { }, actions: [ { - label: _('Create Invoice'), + label: t('Create Invoice'), condition: (doc) => !doc.isNew(), action: async (customer) => { let doc = await frappe.getNewDoc('SalesInvoice'); @@ -28,7 +28,7 @@ export default { }, }, { - label: _('View Invoices'), + label: t('View Invoices'), condition: (doc) => !doc.isNew(), action: (customer) => { router.push({ diff --git a/models/doctype/Party/CustomerList.js b/models/doctype/Party/CustomerList.js index 0118f9b3..4ceb651d 100644 --- a/models/doctype/Party/CustomerList.js +++ b/models/doctype/Party/CustomerList.js @@ -1,7 +1,7 @@ -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; export default { doctype: 'Customer', - title: _('Customers'), + title: t('Customers'), columns: ['name', 'phone', 'outstandingAmount'], }; diff --git a/models/doctype/Party/Party.js b/models/doctype/Party/Party.js index a7931866..336cc716 100644 --- a/models/doctype/Party/Party.js +++ b/models/doctype/Party/Party.js @@ -1,5 +1,5 @@ import frappe from 'frappe'; -import { _ } from 'frappe/utils'; +import { t } from 'frappe'; export default { name: 'Party', @@ -86,7 +86,7 @@ export default { label: 'Address', fieldtype: 'Link', target: 'Address', - placeholder: _('Click to create'), + placeholder: t('Click to create'), inline: true, }, { diff --git a/models/doctype/Party/PartyWidget.vue b/models/doctype/Party/PartyWidget.vue index dd06058e..6ac80727 100644 --- a/models/doctype/Party/PartyWidget.vue +++ b/models/doctype/Party/PartyWidget.vue @@ -1,7 +1,7 @@ diff --git a/src/components/Controls/AttachImage.vue b/src/components/Controls/AttachImage.vue index 2806891e..fa7b28c0 100644 --- a/src/components/Controls/AttachImage.vue +++ b/src/components/Controls/AttachImage.vue @@ -33,7 +33,7 @@ v-show="showEdit" class="absolute bottom-0 text-gray-500 text-center text-xs pt-3 pb-1" > - {{ _('Edit') }} + {{ t('Edit') }}
@@ -58,7 +58,7 @@ export default { methods: { async openFileSelector() { const options = { - title: frappe._('Select Image'), + title: frappe.t('Select Image'), properties: ['openFile'], filters: [{ name: 'Image', extensions: ['png', 'jpg', 'jpeg', 'webp'] }] }; diff --git a/src/components/Controls/Color.vue b/src/components/Controls/Color.vue index 0b46d593..1e70ccf5 100644 --- a/src/components/Controls/Color.vue +++ b/src/components/Controls/Color.vue @@ -40,7 +40,7 @@
this.openNewDoc(), component: { template: ` -
{{ _('Create') }} +
{{ t('Create') }} {{ linkValue }}
`, diff --git a/src/components/Controls/Table.vue b/src/components/Controls/Table.vue index 345fbeb2..30493b69 100644 --- a/src/components/Controls/Table.vue +++ b/src/components/Controls/Table.vue @@ -43,7 +43,7 @@ 'px-3 py-4': size !== 'small' }" > - {{ _('Add Row') }} + {{ t('Add Row') }}
- {{ _('Loading...') }} + {{ t('Loading...') }}
@@ -80,7 +80,7 @@
@@ -89,7 +89,7 @@ @click="addNewFilter" > - {{ _('Add a filter') }} + {{ t('Add a filter') }}
@@ -180,9 +180,9 @@ export default { }, filterAppliedMessage() { if (this.activeFilterCount === 1) { - return this._('1 filter applied'); + return this.t('1 filter applied'); } - return this._('{0} filters applied', [this.activeFilterCount]); + return this.t('{0} filters applied', [this.activeFilterCount]); } } }; diff --git a/src/components/InvoiceCustomizer.vue b/src/components/InvoiceCustomizer.vue index c3285ee8..f67cc850 100644 --- a/src/components/InvoiceCustomizer.vue +++ b/src/components/InvoiceCustomizer.vue @@ -6,7 +6,7 @@

Customize

- {{ _('Save & Close') }} + {{ t('Save & Close') }}
@@ -14,7 +14,7 @@
- {{ _('Company Settings') }} + {{ t('Company Settings') }}
diff --git a/src/components/TwoColumnForm.vue b/src/components/TwoColumnForm.vue index 253be824..2398fdcd 100644 --- a/src/components/TwoColumnForm.vue +++ b/src/components/TwoColumnForm.vue @@ -28,14 +28,14 @@ class="w-1/2 text-gray-900" @click="inlineEditField = null" > - {{ _('Cancel') }} + {{ t('Cancel') }} diff --git a/src/main.js b/src/main.js index 69423217..3263dd56 100644 --- a/src/main.js +++ b/src/main.js @@ -49,9 +49,8 @@ import { outsideClickDirective } from './ui'; }, }, methods: { - _(...args) { - return frappe._(...args); - }, + t: frappe.t, + T: frappe.T, }, }); diff --git a/src/pages/ChartOfAccounts.vue b/src/pages/ChartOfAccounts.vue index 01be1acc..e3dfd63a 100644 --- a/src/pages/ChartOfAccounts.vue +++ b/src/pages/ChartOfAccounts.vue @@ -2,7 +2,7 @@

- {{ _('Chart of Accounts') }} + {{ t('Chart of Accounts') }}