Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Blair2004 committed May 12, 2021
1 parent ec9ac17 commit dd21a53
Show file tree
Hide file tree
Showing 10 changed files with 1,659 additions and 1,595 deletions.
4 changes: 2 additions & 2 deletions app/Console/Commands/ExtractTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ExtractTranslation extends Command
*
* @var string
*/
protected $signature = 'ns:translation {module?} {--extract} {--lang=en} {--symlink}';
protected $signature = 'ns:translate {module?} {--extract} {--lang=en} {--symlink}';

/**
* The console command description.
Expand Down Expand Up @@ -164,7 +164,7 @@ private function extractLocalization( $files )
*/
$this->withProgressBar( $filtered, function( $file ) use ( &$exportable ) {
$fileContent = Storage::disk( 'ns' )->get( $file );
preg_match_all('/\_\_[m]?\(\s*[\'\"\`]([\w\s\"\+\\/\d\'\"\-é&\[\]\@*$#\.\?\%,)\{\}]*)[\'\"\`]\s*\)/', $fileContent, $output_array);
preg_match_all('/\_\_[m]?\(\s*[\'\"\`]([\w\s\"\+\\/\d\'\"\-é&\[\]\@*$#\.\?\%,;)\{\}]*)[\'\"\`]\s*\)/', $fileContent, $output_array);

if ( isset( $output_array[1] ) ) {
foreach( $output_array[1] as $string ) {
Expand Down
2 changes: 1 addition & 1 deletion app/Forms/user-profile/attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
'value' => Auth::user()->attribute->language ?? '',
'type' => 'select',
'options' => Helper::kvToJsOptions( config( 'nexopos.languages' ) ),
'description' => __( 'Choose the language for the currnet account.' ),
'description' => __( 'Choose the language for the current account.' ),
],
]
];
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dashboard/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function showPOS()
}, 15 );

return $this->view( 'pages.dashboard.orders.pos', [
'title' => __( 'Proceeding Order — NexoPOS' ),
'title' => __( 'POS — NexoPOS' ),
'orderTypes' => config( 'nexopos.orders.types' ),
'options' => [
'ns_pos_printing_document' => ns()->option->get( 'ns_pos_printing_document', 'receipt' ),
Expand Down
3,112 changes: 1,560 additions & 1,552 deletions resources/lang/es.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion resources/ts/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Url from "./libraries/url";
import { nsCurrency, nsAbbreviate, nsRawCurrency } from "./filters/declarations";
import CrudHandler from "./libraries/crud-handler";
import { createHooks } from '@wordpress/hooks';
import { __ } from "./libraries/lang";
import { __, __m } from "./libraries/lang";
import popupResolver from "./libraries/popup-resolver";
import popupCloser from "./libraries/popup-closer";
import Echo from "laravel-echo";
Expand All @@ -31,6 +31,7 @@ declare global {
nsHooks: any,
SnackBar: SnackBar,
__: any,
__m: any,
popupResolver: any,
popupCloser: any,
Pusher:any,
Expand All @@ -47,6 +48,7 @@ window.Vue = Vue;
window.moment = <any>moment;
window.Axios = Axios;
window.__ = __;
window.__m = __m;
window.VueRouter = <any>VueRouter;
window.SnackBar = <any>SnackBar;
window.nsHooks = createHooks();
Expand Down
73 changes: 56 additions & 17 deletions resources/ts/lang-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,77 @@ declare const nsHttpClient;
declare const RxJS;
class NsLanguage {
private languages = {};
private scripts = [];
private callbacks = [];

constructor() {
this.boot();
}

async boot() {
return await this.loadJson();
this.loadJson();
}

loadJson() {
return new Promise( ( resolve, reject ) => {

const that = this;

for( let i = 0 ; i < ns.langFiles.length ; i++ ) {
const promises = [];

for( let namespace in ns.langFiles ) {
promises.push( new Promise( ( resolve, reject ) => {
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
xhttp.onreadystatechange = ( e ) => {
if ( (<XMLHttpRequest>e.target).readyState == 4 && (<XMLHttpRequest>e.target).status == 200) {
const result = JSON.parse( xhttp.responseText );

for( let key in result ) {
that.languages[ key ] = result[ key ];
if ( this.languages[ namespace ] === undefined ) {
this.languages[ namespace ] = new Object;
}

this.languages[ namespace ][ key ] = result[ key ]
}
resolve( this.languages );
}
};
xhttp.open("GET", ns.langFiles[i], true);
xhttp.open("GET", ns.langFiles[namespace], true);
xhttp.send();
}
}));
}

Promise.all( promises ).then( () => {
this.loadReadyScripts();
this.loadReadyCallbacks();
});
}

getEntries() {
return this.languages;
loadReadyScripts() {
for( let i = 0; i < this.scripts.length ; i++ ) {
// get some kind of XMLHttpRequest
const xhrObj = new XMLHttpRequest();
// open and send a synchronous request
xhrObj.open('GET', this.scripts[i], false);
xhrObj.send('');
// add the returned content to a newly created script tag
const se = document.createElement('script');
se.type = "text/javascript";
se.text = xhrObj.responseText;
document.body.appendChild(se);
}
}

loadReadyCallbacks() {
this.callbacks.forEach( callback => callback() );
}

onReadyCallback( callback ) {
this.callbacks.push( callback );
}

onReadyScript( script ) {
if ( script.length !== undefined ) {
this.scripts.push( ...script );
} else {
this.scripts.push( script );
}
}

getEntries( namespace ) {
return this.languages[ namespace ] || false;
}
}

Expand Down
9 changes: 6 additions & 3 deletions resources/ts/libraries/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { nsHttpClient } from "@/bootstrap";

declare const nsLanguage;

export const __ = function( text ) {
console.log( nsLanguage.getEntries()[ text ] );
return nsLanguage.getEntries()[ text ] || text;
export const __ = function( text, namespace = 'NexoPOS' ) {
return nsLanguage.getEntries( namespace ) ? nsLanguage.getEntries( namespace )[ text ] : text;
}

export const __m = function( text, namespace ) {
return nsLanguage.getEntries( namespace ) ? nsLanguage.getEntries( namespace )[ text ] : text;
}
2 changes: 1 addition & 1 deletion resources/views/layout/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
window.ns.language = '{{ app()->getLocale() }}';
window.ns.langFiles = <?php echo json_encode( Hook::filter( 'ns.langFiles', [
asset( "/lang/" . app()->getLocale() . ".json" ),
'NexoPOS' => asset( "/lang/" . app()->getLocale() . ".json" ),
]));?>
</script>
<script src="{{ asset( 'js/lang-loader.js' ) }}"></script>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layout/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
window.ns.language = '{{ app()->getLocale() }}';
window.ns.langFiles = <?php echo json_encode( Hook::filter( 'ns.langFiles', [
asset( "/lang/" . app()->getLocale() . ".json" ),
'NexoPOS' => asset( "/lang/" . app()->getLocale() . ".json" ),
]));?>
</script>
<script src="{{ asset( 'js/lang-loader.js' ) }}"></script>
Expand Down
44 changes: 28 additions & 16 deletions resources/views/pages/dashboard/orders/pos.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,42 @@
@endsection

@section( 'layout.base.body' )
<div id="pos-app" class="h-full w-full">
<div id="pos-app" class="h-full w-full relative">
<ns-pos></ns-pos>
<div id="loader" class="top-0 anim-duration-500 fade-in-entrance left-0 absolute w-full h-full flex flex-col items-center justify-center bg-gray-200">
<img src="{{ asset( 'svg/nexopos-variant-1.svg' ) }}" class="w-32" alt="POS">
<p class="font-semibold py-2 text-gray-700">{{ __( 'Loading...' ) }}</p>
</div>
</div>
@endsection

@section( 'layout.base.footer' )
@parent
<script src="{{ asset( 'js/pos-init.js' ) }}"></script>
<script>
POS.defineTypes( @json( $orderTypes ) );
POS.defineOptions( @json( $options ) );
POS.defineSettings({
barcode_search : true,
text_search : false,
breadcrumb : [],
products_queue : [],
urls : @json( $urls )
});
nsLanguage.onReadyScript([
`{{ asset( 'js/pos-init.js' ) }}`,
`{{ asset( 'js/pos.js' ) }}`
]);
nsLanguage.onReadyCallback( () => {
const loader = document.getElementById( 'loader' );
loader.classList.remove( 'fade-in-entrance' );
loader.classList.add( 'fade-out-exit' );
POS.definedPaymentsType( @json( $paymentTypes ) );
</script>
<script src="{{ asset( 'js/pos.js' ) }}"></script>
<script>
document.addEventListener( 'DOMContentLoaded', () => {
setTimeout( () => {
loader.remove();
}, 500 );
POS.defineTypes( <?php echo json_encode( $orderTypes );?>);
POS.defineOptions( <?php echo json_encode( $options );?>);
POS.defineSettings({
barcode_search : true,
text_search : false,
breadcrumb : [],
products_queue : [],
urls : <?php echo json_encode( $urls );?>
});
POS.definedPaymentsType( <?php echo json_encode( $paymentTypes );?> );
POS.reset();
});
</script>
Expand Down

0 comments on commit dd21a53

Please sign in to comment.