-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathLangListService.php
More file actions
33 lines (25 loc) · 964 Bytes
/
LangListService.php
File metadata and controls
33 lines (25 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace UFirst\LangImportExport;
use Illuminate\Support\Arr;
use Lang;
class LangListService {
public function loadLangList($locale, $group) {
$translations = Lang::getLoader()->load($locale, $group);
$translations_with_prefix = Arr::dot(array($group => $translations));
return $translations_with_prefix;
}
public function writeLangList($locale, $group, $new_translations) {
$translations = Lang::getLoader()->load($locale, $group);
foreach($new_translations as $key => $value) {
Arr::set($translations, $key, $value);
}
$header = "<?php\n\nreturn ";
$language_file = base_path("resources/lang/{$locale}/{$group}.php");
if (is_writable($language_file) && ($fp = fopen($language_file, 'w')) !== FALSE) {
fputs($fp, $header.var_export($translations[$group], TRUE).";\n");
fclose($fp);
} else {
throw new \Exception("Cannot open language file at {$language_file} for writing. Check the file permissions.");
}
}
}