From 6d6084728d62179ffc6a04ef6efeed72a7f2fd05 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 23 Mar 2014 14:19:54 +0200 Subject: [PATCH] Working on multi-language support --- .../packages/anahkiasen/former/config.php | 2 +- app/controllers/InvoiceController.php | 1 + ...2014_03_19_201454_add_language_support.php | 1 + app/lang/en/fields.php | 54 +++++++++++++++++++ app/lang/en/messages.php | 0 app/lang/en/texts.php | 28 ---------- app/lang/pt_BR/{texts.php => fields.php} | 0 app/models/User.php | 32 +++++++++++ app/views/invoices/edit.blade.php | 33 ++++++------ public/js/script.js | 46 ++++++++-------- 10 files changed, 129 insertions(+), 68 deletions(-) create mode 100644 app/lang/en/fields.php create mode 100644 app/lang/en/messages.php delete mode 100644 app/lang/en/texts.php rename app/lang/pt_BR/{texts.php => fields.php} (100%) diff --git a/app/config/packages/anahkiasen/former/config.php b/app/config/packages/anahkiasen/former/config.php index 327019638f9d..fe5eff734968 100755 --- a/app/config/packages/anahkiasen/former/config.php +++ b/app/config/packages/anahkiasen/former/config.php @@ -48,7 +48,7 @@ //////////////////////////////////////////////////////////////////// // Where Former should look for translations - 'translate_from' => 'texts', + 'translate_from' => 'fields', // An array of attributes to automatically translate 'translatable' => array( diff --git a/app/controllers/InvoiceController.php b/app/controllers/InvoiceController.php index 6c3326707225..c4e233e41cb9 100755 --- a/app/controllers/InvoiceController.php +++ b/app/controllers/InvoiceController.php @@ -223,6 +223,7 @@ class InvoiceController extends \BaseController { 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), + 'invoiceLabels' => Auth::user()->getInvoiceLabels(), 'frequencies' => array( 1 => 'Weekly', 2 => 'Two weeks', diff --git a/app/database/migrations/2014_03_19_201454_add_language_support.php b/app/database/migrations/2014_03_19_201454_add_language_support.php index 5e63292a7d63..b48683073e2f 100644 --- a/app/database/migrations/2014_03_19_201454_add_language_support.php +++ b/app/database/migrations/2014_03_19_201454_add_language_support.php @@ -23,6 +23,7 @@ class AddLanguageSupport extends Migration { DB::table('languages')->insert(['name' => 'Italian', 'locale' => 'it']); DB::table('languages')->insert(['name' => 'German', 'locale' => 'de']); DB::table('languages')->insert(['name' => 'French', 'locale' => 'fr']); + DB::table('languages')->insert(['name' => 'Brazilian Portuguese', 'locale' => 'pt_BR']); Schema::table('accounts', function($table) { diff --git a/app/lang/en/fields.php b/app/lang/en/fields.php new file mode 100644 index 000000000000..10f5d738c39a --- /dev/null +++ b/app/lang/en/fields.php @@ -0,0 +1,54 @@ + 'Organization', + 'name' => 'Name', + 'website' => 'Website', + 'work_phone' => 'Phone', + 'address' => 'Address', + 'address1' => 'Street', + 'address2' => 'Apt/Suite', + 'city' => 'City', + 'state' => 'State/Province', + 'postal_code' => 'Postal Code', + 'country_id' => 'Country', + 'contacts' => 'Contacts', + 'first_name' => 'First Name', + 'last_name' => 'Last Name', + 'phone' => 'Phone', + 'email' => 'Email', + 'additional_info' => 'Additional Info', + 'payment_terms' => 'Payment Terms', + 'currency_id' => 'Currency', + 'size_id' => 'Size', + 'industry_id' => 'Industry', + 'private_notes' => 'Private Notes', + + // invoice + 'invoice' => 'Invoice', + 'client' => 'Client', + 'invoice_date' => 'Invoice Date', + 'due_date' => 'Due Date', + 'invoice_number' => 'Invoice Number', + 'invoice_number_short' => 'Invoice #', + 'po_number' => 'PO Number', + 'po_number_short' => 'PO #', + 'frequency_id' => 'How often', + 'dicount' => 'Discount', + 'taxes' => 'Taxes', + 'tax' => 'Tax', + 'item' => 'Item', + 'description' => 'Description', + 'unit_cost' => 'Unit Cost', + 'quantity' => 'Quantity', + 'line_total' => 'Line Total', + 'subtotal' => 'Subtotal', + 'paid_to_date' => 'Paid to Date', + 'balance_due' => 'Balance Due', + 'invoice_design_id' => 'Design', + 'terms' => 'Terms', + 'your_invoice' => 'Your Invoice', + +); \ No newline at end of file diff --git a/app/lang/en/messages.php b/app/lang/en/messages.php new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/app/lang/en/texts.php b/app/lang/en/texts.php deleted file mode 100644 index 97fa8600f494..000000000000 --- a/app/lang/en/texts.php +++ /dev/null @@ -1,28 +0,0 @@ - 'Organization', - 'name' => 'Name', - 'website' => 'Website', - 'work_phone' => 'Phone', - 'address' => 'Address', - 'address1' => 'Street', - 'address2' => 'Apt/Suite', - 'city' => 'City', - 'state' => 'State/Province', - 'postal_code' => 'Postal Code', - 'country_id' => 'Country', - 'contacts' => 'Contacts', - 'first_name' => 'First Name', - 'last_name' => 'Last Name', - 'phone' => 'Phone', - 'email' => 'Email', - 'additional_info' => 'Additional Info', - 'payment_terms' => 'Payment Terms', - 'currency_id' => 'Currency', - 'size_id' => 'Size', - 'industry_id' => 'Industry', - 'private_notes' => 'Private Notes', - -); \ No newline at end of file diff --git a/app/lang/pt_BR/texts.php b/app/lang/pt_BR/fields.php similarity index 100% rename from app/lang/pt_BR/texts.php rename to app/lang/pt_BR/fields.php diff --git a/app/models/User.php b/app/models/User.php index f9fb73acb83b..2d2d03ee2bf8 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -110,6 +110,38 @@ class User extends ConfideUser implements UserInterface, RemindableInterface return $language->locale; } + public function getInvoiceLabels() + { + $data = []; + $fields = [ + 'invoice', + 'invoice_date', + 'due_date', + 'invoice_number', + 'po_number', + 'dicount', + 'taxes', + 'tax', + 'item', + 'description', + 'unit_cost', + 'quantity', + 'line_total', + 'subtotal', + 'paid_to_date', + 'balance_due', + 'terms', + 'your_invoice', + ]; + + foreach ($fields as $field) + { + $data[$field] = trans("fields.$field"); + } + + return $data; + } + public function showGreyBackground() { return !$this->theme_id || in_array($this->theme_id, [2, 3, 5, 6, 7, 8, 10, 11, 12]); diff --git a/app/views/invoices/edit.blade.php b/app/views/invoices/edit.blade.php index 56d7e70c18eb..d797854732a0 100755 --- a/app/views/invoices/edit.blade.php +++ b/app/views/invoices/edit.blade.php @@ -70,7 +70,7 @@ ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('') }}
- {{ Former::select('frequency_id')->label('How often')->options($frequencies)->data_bind("value: frequency_id") }} + {{ Former::select('frequency_id')->options($frequencies)->data_bind("value: frequency_id") }} {{ Former::text('start_date')->data_bind("datePicker: start_date, valueUpdate: 'afterkeydown'") ->data_date_format(Session::get(SESSION_DATE_PICKER_FORMAT))->append('') }} {{ Former::text('end_date')->data_bind("datePicker: end_date, valueUpdate: 'afterkeydown'") @@ -90,10 +90,10 @@
- {{ Former::text('invoice_number')->label('Invoice #')->data_bind("value: invoice_number, valueUpdate: 'afterkeydown'") }} - {{ Former::text('po_number')->label('PO #')->data_bind("value: po_number, valueUpdate: 'afterkeydown'") }} + {{ Former::text('invoice_number')->label(trans('fields.invoice_number_short'))->data_bind("value: invoice_number, valueUpdate: 'afterkeydown'") }} + {{ Former::text('po_number')->label(trans('fields.po_number_short'))->data_bind("value: po_number, valueUpdate: 'afterkeydown'") }} {{ Former::text('discount')->data_bind("value: discount, valueUpdate: 'afterkeydown'")->append('%') }} - {{-- Former::select('currency_id')->label('Currency')->addOption('', '')->fromQuery($currencies, 'name', 'id')->data_bind("value: currency_id") --}} + {{-- Former::select('currency_id')->addOption('', '')->fromQuery($currencies, 'name', 'id')->data_bind("value: currency_id") --}}
@@ -210,7 +210,7 @@ - {{ Former::select('invoice_design_id')->label('Design')->style('display:inline;width:120px')->raw() + {{ Former::select('invoice_design_id')->style('display:inline;width:120px')->raw() ->fromQuery($invoiceDesigns, 'name', 'id')->data_bind("value: invoice_design_id") }} @@ -291,16 +291,16 @@ {{ Former::legend('Organization') }} {{ Former::text('name')->data_bind("value: name, valueUpdate: 'afterkeydown', attr { placeholder: name.placeholder }") }} {{ Former::text('website')->data_bind("value: website, valueUpdate: 'afterkeydown'") }} - {{ Former::text('work_phone')->data_bind("value: work_phone, valueUpdate: 'afterkeydown'")->label('Phone') }} + {{ Former::text('work_phone')->data_bind("value: work_phone, valueUpdate: 'afterkeydown'") }} {{ Former::legend('Address') }} - {{ Former::text('address1')->label('Street')->data_bind("value: address1, valueUpdate: 'afterkeydown'") }} - {{ Former::text('address2')->label('Apt/Suite')->data_bind("value: address2, valueUpdate: 'afterkeydown'") }} + {{ Former::text('address1')->data_bind("value: address1, valueUpdate: 'afterkeydown'") }} + {{ Former::text('address2')->data_bind("value: address2, valueUpdate: 'afterkeydown'") }} {{ Former::text('city')->data_bind("value: city, valueUpdate: 'afterkeydown'") }} - {{ Former::text('state')->label('State/Province')->data_bind("value: state, valueUpdate: 'afterkeydown'") }} + {{ Former::text('state')->data_bind("value: state, valueUpdate: 'afterkeydown'") }} {{ Former::text('postal_code')->data_bind("value: postal_code, valueUpdate: 'afterkeydown'") }} - {{ Former::select('country_id')->addOption('','')->label('Country')->addGroupClass('country_select') + {{ Former::select('country_id')->addOption('','')->addGroupClass('country_select') ->fromQuery($countries, 'name', 'id')->data_bind("dropdown: country_id") }}
@@ -332,11 +332,11 @@ {{ Former::legend('Additional Info') }} {{ Former::select('payment_terms')->addOption('','0')->data_bind('value: payment_terms') ->fromQuery($paymentTerms, 'name', 'num_days') }} - {{ Former::select('currency_id')->addOption('','')->label('Currency')->data_bind('value: currency_id') + {{ Former::select('currency_id')->addOption('','')->data_bind('value: currency_id') ->fromQuery($currencies, 'name', 'id') }} - {{ Former::select('size_id')->addOption('','')->label('Size')->data_bind('value: size_id') + {{ Former::select('size_id')->addOption('','')->data_bind('value: size_id') ->fromQuery($sizes, 'name', 'id') }} - {{ Former::select('industry_id')->addOption('','')->label('Industry')->data_bind('value: industry_id') + {{ Former::select('industry_id')->addOption('','')->data_bind('value: industry_id') ->fromQuery($industries, 'name', 'id') }} {{ Former::textarea('private_notes')->data_bind('value: private_notes') }} @@ -616,9 +616,10 @@ var isRefreshing = false; var needsRefresh = false; + function getPDFString() { var invoice = createInvoiceModel(); - var doc = generatePDF(invoice); + var doc = generatePDF(invoice, invoiceLabels); if (!doc) return; return doc.output('datauristring'); } @@ -1445,10 +1446,10 @@ var products = {{ $products }}; var clients = {{ $clients }}; + var invoiceLabels = {{ json_encode($invoiceLabels) }}; var clientMap = {}; var $clientSelect = $('select#client'); - - + for (var i=0; i 0 ? formatMoney(invoice.discount_amount, invoice.client.currency_id) : false}, - {'Tax': invoice.tax_amount > 0 ? formatMoney(invoice.tax_amount, invoice.client.currency_id) : false}, - {'Paid to Date': formatMoney(invoice.amount - invoice.balance, invoice.client.currency_id)} + {'subtotal': formatMoney(invoice.subtotal_amount, invoice.client.currency_id)}, + {'discount': invoice.discount_amount > 0 ? formatMoney(invoice.discount_amount, invoice.client.currency_id) : false}, + {'tax': invoice.tax_amount > 0 ? formatMoney(invoice.tax_amount, invoice.client.currency_id) : false}, + {'paid_to_date': formatMoney(invoice.amount - invoice.balance, invoice.client.currency_id)} ]; return displayGrid(doc, invoice, data, 300, y, layout, true, 550, rightAlignTitleX) + 10; @@ -1396,6 +1396,7 @@ function displayGrid(doc, invoice, data, x, y, layout, hasheader, rightAlignX, r doc.setFontType('normal'); } + key = invoiceLabels[key]; if (rightAlignTitleX) { marginLeft = rightAlignTitleX - (doc.getStringUnitWidth(key) * doc.internal.getFontSize()); } else { @@ -1426,7 +1427,7 @@ function displayNotesAndTerms(doc, layout, invoice, y) if (invoice.terms) { doc.setFontType("bold"); - doc.text(layout.marginLeft, y, "Terms"); + doc.text(layout.marginLeft, y, invoiceLabels.terms); y += 16; doc.setFontType("normal"); doc.text(layout.marginLeft, y, invoice.terms); @@ -1502,26 +1503,25 @@ function getInvoiceTaxRate(invoice) { function displayInvoiceHeader(doc, invoice, layout) { - var costX = layout.unitCostRight - (doc.getStringUnitWidth('Unit Cost') * doc.internal.getFontSize()); - var qtyX = layout.qtyRight - (doc.getStringUnitWidth('Quantity') * doc.internal.getFontSize()); - var taxX = layout.taxRight - (doc.getStringUnitWidth('Tax') * doc.internal.getFontSize()); - var totalX = layout.lineTotalRight - (doc.getStringUnitWidth('Line Total') * doc.internal.getFontSize()); + var costX = layout.unitCostRight - (doc.getStringUnitWidth(invoiceLabels.unit_cost) * doc.internal.getFontSize()); + var qtyX = layout.qtyRight - (doc.getStringUnitWidth(invoiceLabels.quantity) * doc.internal.getFontSize()); + var taxX = layout.taxRight - (doc.getStringUnitWidth(invoiceLabels.tax) * doc.internal.getFontSize()); + var totalX = layout.lineTotalRight - (doc.getStringUnitWidth(invoiceLabels.line_total) * doc.internal.getFontSize()); - doc.text(layout.marginLeft, layout.tableTop, 'Item'); - doc.text(layout.descriptionLeft, layout.tableTop, 'Description'); - doc.text(costX, layout.tableTop, 'Unit Cost'); - doc.text(qtyX, layout.tableTop, 'Quantity'); - doc.text(totalX, layout.tableTop, 'Line Total'); + doc.text(layout.marginLeft, layout.tableTop, invoiceLabels.item); + doc.text(layout.descriptionLeft, layout.tableTop, invoiceLabels.description); + doc.text(costX, layout.tableTop, invoiceLabels.unit_cost); + doc.text(qtyX, layout.tableTop, invoiceLabels.quantity); + doc.text(totalX, layout.tableTop, invoiceLabels.line_total); if (invoice.has_taxes) { - doc.text(taxX, layout.tableTop, 'Tax'); + doc.text(taxX, layout.tableTop, invoiceLabels.tax); } } function displayInvoiceItems(doc, invoice, layout) { - doc.setFontType("normal"); var line = 1;