Skip to content

Commit 2e0b576

Browse files
localization on backend and frontend completed, added hindi language translations
1 parent b29f412 commit 2e0b576

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+680
-263
lines changed

app/Console/Commands/OriginBackup.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,17 @@ public function handle()
7676
$this->backupFiles(true); // backup user uploaded files
7777
}
7878

79-
$this->info('Backup has been created successfully.');
79+
$this->info(__('Backup created successfully'));
8080
}
8181
} else {
82-
$this->error('Backups are not enabled. Please enable it from Settings');
82+
$this->error(__('Backups are not enabled. Please enable it from Settings'));
8383
}
8484
} else {
85-
$this->error('Backups are not enabled. Please enable it from Settings');
85+
$this->error(__('Backups are not enabled. Please enable it from Settings'));
8686
}
8787
} catch (ProcessFailedException $e) {
88-
logger()->error('Backup process failed: ' . str_replace("'", "", $e->getMessage()));
89-
$this->error('Backup process has been failed.');
88+
logger()->error('Backup creation failed: ' . str_replace("'", "", $e->getMessage()));
89+
$this->error(__('Backup creation failed'));
9090
}
9191
}
9292

app/Http/Controllers/ActivityController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function getLatestActivities($size)
179179
foreach ($activities as $act) {
180180
$icon = $act->icon;
181181
$description = '';
182-
$user = (auth()->user()->id == $act->user_id) ? "You" : $act->user;
182+
$user = (auth()->user()->id == $act->user_id) ? __('You') : $act->user;
183183
$time_diff = $act->created_at->diffForHumans();
184184

185185
if ($act->module == "Auth") {
@@ -189,7 +189,7 @@ public function getLatestActivities($size)
189189
$description = $user . " " . __('logged out');
190190
}
191191
} else {
192-
$activity_link = $act->module . ': ' . $act->form_title;
192+
$activity_link = __($act->module) . ': ' . $act->form_title;
193193

194194
if ($act->action == "Create") {
195195
$description = __('New') . " " . $activity_link . " " . __('created by') . " " . $user;

app/Http/Controllers/Auth/LoginController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function afterSuccessLogin($request)
114114
if ($request->ajax()) {
115115
return response()->json([
116116
'success' => true,
117-
'msg' => 'User successfully logged in'
117+
'msg' => __('Successfully logged in')
118118
], 200);
119119
} else {
120120
if ($request->filled('redirect_to')) {

app/Http/Controllers/AutocompleteController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ public function getUniverseResults($query)
267267
if ($data && count($data)) {
268268
foreach ($data as $idx => $record) {
269269
array_push($result, [
270-
'label' => $table['module_label'] . ' <b>' . __(strval($record->{$table['fetch_fields'][1]})) . '</b>',
271-
'value' => $table['module_label'] . ' ' . __(strval($record->{$table['fetch_fields'][1]})),
270+
'label' => $table['module_label'] . ' <b>' . strval($record->{$table['fetch_fields'][1]}) . '</b>',
271+
'value' => $table['module_label'] . ' ' . strval($record->{$table['fetch_fields'][1]}),
272272
'redirect_to' => route('show.doc', ['slug' => $table['module_slug'], 'id' => $record->id])
273273
]);
274274
}

app/Http/Controllers/BackupController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function show(Request $request)
8686

8787
public function download(Request $request, $name)
8888
{
89-
$msg = __('You are not authorized to view this page');
89+
$msg = __('You are not authorized to download backups');
9090

9191
if (auth()->user()->role == "Administrator" && auth()->user()->username == "admin") {
9292
if ($name) {
@@ -122,7 +122,7 @@ public function download(Request $request, $name)
122122

123123
public function delete(Request $request, $name)
124124
{
125-
$msg = __('You are not authorized');
125+
$msg = __('You are not authorized to delete backups');
126126
$success = false;
127127

128128
if (auth()->user()->role == "Administrator" && auth()->user()->username == "admin") {
@@ -168,7 +168,7 @@ public function delete(Request $request, $name)
168168

169169
public function create(Request $request)
170170
{
171-
$msg = __('You are not authorized');
171+
$msg = __('You are not authorized to create backups');
172172
$success = false;
173173

174174
if (auth()->user()->role == "Administrator" && auth()->user()->username == "admin") {

app/Http/Controllers/CommonController.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use File;
88
use App\Module;
99
use App\Activity;
10+
use App\User;
1011

1112
trait CommonController
1213
{
@@ -228,4 +229,26 @@ public function getTableSchema($table, $get_nullable = false)
228229

229230
return $table_schema;
230231
}
232+
233+
// update locale for user and update the session translations
234+
public function updateLocale($locale)
235+
{
236+
$user_updated = User::where('id', auth()->user()->id)
237+
->update(['locale' => $locale, 'updated_at' => date('Y-m-d H:i:s')]);
238+
239+
if ($user_updated) {
240+
session()->put('locale', $locale);
241+
app()->setLocale($locale);
242+
session()->forget('translations');
243+
244+
$translations = [];
245+
246+
if ($locale != 'en' && File::exists(resource_path('lang/' . $locale . '.json'))) {
247+
$translations = File::get(resource_path('lang/' . $locale . '.json'));
248+
$translations = json_decode($translations, true);
249+
}
250+
251+
session()->put('translations', $translations);
252+
}
253+
}
231254
}

app/Http/Controllers/FormController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function saveForm($request, $module, $action, $record_exists = null)
276276
// if record already exists in database while creating
277277
session()->flash('success', false);
278278

279-
$message = __($module['display_name']) . ': "' . $request->get($module['link_field']) . '" ' . __('already exist');
279+
$message = __($module['display_name']) . ': "' . $request->get($module['link_field']) . '" ' . __('already exists');
280280
return $this->sendResponse(400, $message);
281281
} elseif ($action == "update" && $request->get($module['link_field']) != $module['link_field_value']) {
282282
// if link field value is not matching the request link value

app/Http/Controllers/LanguageController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function beforeDelete($id)
4141

4242
if ($language) {
4343
if ($language->locale == 'en') {
44-
throw new Exception(__('Cannot delete system default locale: en'));
44+
throw new Exception(__('Cannot delete system default language: en'));
4545
}
4646
} else {
4747
throw new Exception(__('No such language found'));

app/Http/Controllers/ListViewController.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ public function prepareListViewData($request)
8787
{
8888
$user_role = auth()->user()->role;
8989
$table_schema = $this->getTableSchema($this->module['table_name']);
90+
$rows = [];
91+
$table_columns = [];
9092

9193
if ($request->ajax() || $request->is('api/*')) {
9294
try {
9395
$rows = $this->getRecords($request, $table_schema);
9496
} catch(Exception $e) {
9597
throw new Exception(str_replace("'", "", $e->getMessage()));
9698
}
97-
} else {
98-
$rows = [];
9999
}
100100

101101
if ($user_role == 'System Administrator') {
@@ -106,11 +106,31 @@ public function prepareListViewData($request)
106106
$can_delete = $this->roleWiseModules($user_role, "Delete", $this->module['name']);
107107
}
108108

109+
foreach ($table_schema as $column_name => $column_type) {
110+
if (!in_array($column_name, ['avatar', 'password', 'remember_token'])) {
111+
$column_label = str_replace("Id", "ID", awesome_case($column_name));
112+
$column_label = explode(" ", $column_label);
113+
114+
foreach ($column_label as $c_idx => $col_part) {
115+
if ($col_part == 'Bg') {
116+
$column_label[$c_idx] = 'Background';
117+
}
118+
}
119+
120+
$column_label = implode(" ", $column_label);
121+
122+
$table_columns[$column_name] = [
123+
'label' => __($column_label),
124+
'type' => $column_type
125+
];
126+
}
127+
}
128+
109129
$list_view_data = [
110130
'module' => $this->module,
111131
'rows' => $rows,
112132
'columns' => array_map('trim', explode(",", $this->module['list_view_columns'])),
113-
'table_columns' => $table_schema,
133+
'table_columns' => $table_columns,
114134
'can_create' => $can_create,
115135
'can_delete' => $can_delete
116136
];
@@ -279,7 +299,7 @@ public function updateSorting(Request $request)
279299

280300
$data = [
281301
'success' => true,
282-
'msg' => __('List View sorting fields updated for current module')
302+
'msg' => __('Sorting fields has been updated')
283303
];
284304
}
285305
} else {

app/Http/Controllers/ReportController.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ public function show()
2020
{
2121
if (in_array(auth()->user()->role, ["System Administrator", "Administrator"])) {
2222
$app_reports = config('reports');
23+
24+
foreach ($app_reports as $report_name => $report) {
25+
if (isset($report['allowed_roles']) && $report['allowed_roles'] && !in_array(auth()->user()->role, $report['allowed_roles'])) {
26+
unset($app_reports[$report_name]);
27+
}
28+
}
29+
2330
return view('admin.layouts.origin.reports')->with(['data' => $app_reports]);
2431
} else {
2532
return back()->withInput()->with(['msg' => __('You are not authorized to view "Reports"')]);
@@ -68,7 +75,7 @@ public function showReport(Request $request, $report_name)
6875
$report_data['module_new_record'] = route('new.doc', ['slug' => $report_data['module_slug']]);
6976
}
7077
} else {
71-
throw new Exception('"' . $report_module . '" Module does not exist. Please update the module in ' . Str::studly($report_name) . ' controller');
78+
throw new Exception('"' . $report_module . '" module does not exist. Please update the module in ' . Str::studly($report_name) . ' controller');
7279
}
7380
}
7481

app/Http/Controllers/SettingsController.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33
namespace App\Http\Controllers;
44

55
use DB;
6+
use App\Language;
67
use App\Http\Controllers\CommonController;
78
use Illuminate\Http\Request;
89

910
class SettingsController extends Controller
1011
{
1112
use CommonController;
1213

13-
// Show app settings page
1414
public function show()
1515
{
1616
$data['oc_settings'] = $this->getAppSetting();
1717

18+
$language = Language::select('name', 'locale')
19+
->where('locale', app()->getLocale())
20+
->first();
21+
22+
if ($language) {
23+
$data['oc_settings']['language'] = $language->name;
24+
$data['oc_settings']['locale'] = $language->locale;
25+
}
26+
1827
$settings_data = [
1928
'form_data' => isset($data) ? $data : [],
2029
'form_title' => 'Settings',
@@ -31,12 +40,27 @@ public function show()
3140
return view('admin.templates.form_view', $settings_data);
3241
}
3342

34-
// Save app settings
3543
public function save(Request $request)
3644
{
3745
$settings_data = $request->all();
3846
unset($settings_data["_token"]);
3947

48+
if (isset($settings_data['language'])) {
49+
unset($settings_data["language"]);
50+
}
51+
52+
$locale = app()->getLocale();
53+
$locale_updated = false;
54+
55+
if (isset($settings_data['locale']) && trim($settings_data['locale'])) {
56+
if (trim($settings_data['locale']) != $locale) {
57+
$locale = trim($settings_data['locale']);
58+
$locale_updated = true;
59+
}
60+
61+
unset($settings_data['locale']);
62+
}
63+
4064
foreach ($settings_data as $setting => $value) {
4165
$result = DB::table('oc_settings')
4266
->where('field_name', $setting)
@@ -54,6 +78,10 @@ public function save(Request $request)
5478

5579
$this->putAppSettingsInSession();
5680

81+
if ($locale_updated) {
82+
$this->updateLocale($locale);
83+
}
84+
5785
$data = [
5886
'success' => true,
5987
'msg' => __('App settings successfully saved')

app/Http/Controllers/TranslationController.php

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use File;
66
use Exception;
7+
use DB;
78
use App\Translation;
89
use App\Http\Controllers\CommonController;
910
use Illuminate\Http\Request;
@@ -35,32 +36,64 @@ public function beforeSave($request)
3536
$locale = trim($request->get('locale'));
3637
$from = trim($request->get('from'));
3738
$to = trim($request->get('to'));
39+
$proceed = true;
40+
$error_msg = null;
3841

39-
$transData = $this->openTranslationFile($locale);
42+
$existing = Translation::select('id', 'from', 'locale')
43+
->where(DB::raw('BINARY `from`'), '=', $from)
44+
->where('locale', $locale);
4045

4146
if ($request->filled('id')) {
42-
$existing = Translation::select('id', 'from')
43-
->where('id', trim($request->get('id')))
44-
->first();
47+
$existing = $existing->where('id', '!=', trim($request->get('id')));
48+
}
49+
50+
$existing = $existing->first();
51+
52+
if ($existing) {
53+
$proceed = false;
54+
$error_msg = __('Record already exist. Please enter different value for') . ': ' . __('From');
55+
}
4556

46-
if (isset($transData[$existing->from]) || isset($transData[$from])) {
47-
if ($from != $existing->from) {
48-
unset($transData[$existing->from]);
57+
if ($proceed) {
58+
$transData = $this->openTranslationFile($locale);
59+
60+
if ($request->filled('id')) {
61+
$existing = Translation::select('id', 'from')
62+
->where('id', trim($request->get('id')))
63+
->first();
64+
65+
if (isset($transData[$existing->from]) || isset($transData[$from])) {
66+
if ($from != $existing->from) {
67+
unset($transData[$existing->from]);
68+
}
4969
}
5070
}
51-
}
5271

53-
$transData[$from] = $to;
54-
$saved = $this->saveTranslationFile($locale, $transData);
72+
$transData[$from] = $to;
73+
$saved = $this->saveTranslationFile($locale, $transData);
5574

56-
if (!$saved) {
57-
throw new Exception(__('Cannot save translation file. Please try again'));
75+
if (!$saved) {
76+
throw new Exception(__('Cannot save translation file. Please try again'));
77+
}
78+
} else {
79+
throw new Exception($error_msg);
5880
}
5981
} else {
6082
throw new Exception(__('Please provide Language, From & To'));
6183
}
6284
}
6385

86+
// put all functions to be performed after save
87+
public function afterSave($data)
88+
{
89+
$table_name = $data['table_name'];
90+
$form_data = $data['form_data'][$table_name];
91+
92+
if ($form_data['locale'] == app()->getLocale()) {
93+
session()->forget('translations');
94+
}
95+
}
96+
6497
// put all functions to be performed after delete
6598
public function afterDelete($data)
6699
{
@@ -90,6 +123,10 @@ public function afterDelete($data)
90123
}
91124
}
92125
}
126+
127+
if ($locale == app()->getLocale()) {
128+
session()->forget('translations');
129+
}
93130
}
94131

95132
public function openTranslationFile($locale)

app/Http/Controllers/UserController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function verifyUserEmail(Request $request, $token)
124124
$msg = __('Invalid Token or Token Expired');
125125
}
126126
} else {
127-
$msg = __('Please provide token to verify email address');
127+
$msg = __('Please provide token to verify email');
128128
}
129129

130130
if ($request->ajax()) {

0 commit comments

Comments
 (0)