Skip to content

Commit

Permalink
get lingo translation through blade instead of js
Browse files Browse the repository at this point in the history
…

…
  • Loading branch information
ctf0 committed Nov 14, 2017
1 parent d033ff5 commit e32bd67
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Controllers/LingoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LingoController extends Controller

public function __construct(Filesystem $file)
{
$this->lang_path = resource_path() . '/lang';
$this->lang_path = resource_path('lang');
$this->langDirs = $file->directories($this->lang_path);
$this->file = $file;
}
Expand Down
20 changes: 20 additions & 0 deletions src/LingoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ public function packagePublish()
$this->publishes([
__DIR__ . '/resources/lang' => resource_path('lang/vendor/Lingo'),
], 'trans');

$this->viewComp();
}

protected function viewComp()
{
$path = resource_path('lang/vendor/Lingo');
$current = app()->getLocale();
$fall_back = config('app.fallback_locale');
$file_name = 'messages.php';

$trans = file_exists("$path/$current/$file_name")
? include "$path/$current/$file_name"
: include "$path/$fall_back/$file_name";

view()->composer('Lingo::*', function ($view) use ($trans) {
$view->with([
'lingo_trans' => json_encode($trans),
]);
});
}

/**
Expand Down
28 changes: 6 additions & 22 deletions src/resources/assets/js/Main/container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export default {
name: 'lingo',
mixins: [Forms],
props: [
'currentLocale',
'scanForMissingRoute',
'addNewLocaleRoute',
'addNewFileRoute',
Expand All @@ -17,12 +16,12 @@ export default {
'selectedFileDataRoute',
'deleteFileRoute',
'deleteLocaleRoute',
'saveFileRoute'
'saveFileRoute',
'lingoTrans'
],
data() {
return {
activeTab: 'default-tab',
lingoTrans: '',
new_locale: null,
new_file: null,
new_vendor: null,
Expand Down Expand Up @@ -54,17 +53,14 @@ export default {
return this.dirsList && this.dirsList.includes(this.new_vendor) || false
}
},
created() {
this.getLingoTrans()
},
beforeMount() {
this.preVisited()
},
updated() {
this.reflowTable()
},
methods: {
// main
// local-storage
preVisited() {
let ls = JSON.parse(localStorage.getItem('lingo'))
Expand All @@ -91,18 +87,6 @@ export default {
)
}
},
getLingoTrans() {
$.post(this.selectedFileDataRoute, {
'file_name': 'messages.php',
'dir_name': 'Lingo'
}, (data) => {
if (data.success) {
this.lingoTrans = data.message.all
}
}).fail(() => {
this.failedAjax()
})
},
// tabs
activeTabIs(tab) {
Expand Down Expand Up @@ -148,7 +132,7 @@ export default {
}, 10)
},
trans(key) {
return this.lingoTrans[key][this.currentLocale]
return this.lingoTrans[key]
},
// notifs
Expand Down Expand Up @@ -179,10 +163,10 @@ export default {
})
},
failedAjax() {
this.showNotif(this.trans('ajax_fail') || 'Ajax Call Failed', 'black')
this.showNotif(this.trans('ajax_fail'), 'black')
},
missingVal(msg = null) {
this.showNotif(msg || this.trans('no_val') || 'Missing Value', 'warning')
this.showNotif(msg || this.trans('no_val'), 'warning')
}
},
watch: {
Expand Down
4 changes: 2 additions & 2 deletions src/resources/views/lingo-bulma.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<div class="column">

<lingo inline-template
current-locale="{{ app()->getLocale() }}"
scan-for-missing-route="{{ route('lingo.scan_for_missing') }}"
add-new-locale-route="{{ route('lingo.add_new_locale') }}"
add-new-file-route="{{ route('lingo.add_new_file') }}"
Expand All @@ -35,7 +34,8 @@
selected-file-data-route="{{ route('lingo.get_file_data') }}"
delete-file-route="{{ route('lingo.delete_file') }}"
delete-locale-route="{{ route('lingo.delete_locale') }}"
save-file-route="{{ route('lingo.save_file_data') }}">
save-file-route="{{ route('lingo.save_file_data') }}"
:lingo-trans="{{ $lingo_trans }}">
<div>

<div class="columns">
Expand Down

0 comments on commit e32bd67

Please sign in to comment.