Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6434bb7

Browse files
committed
fix(JSON Exports): added to_translate to translation so that it's easier for the TWB workflows
1 parent a942a39 commit 6434bb7

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

v5/Console/Commands/GenerateEntityTranslationsJson.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ private function getCategories()
102102
*/
103103
private function makeTranslatableItem($item, $output_type, $context, $translatable_field)
104104
{
105-
$toTranslate = $item->$translatable_field;
106-
if ($toTranslate === null || $toTranslate === "") {
105+
$to_translate = $item->$translatable_field;
106+
if ($to_translate === null || $to_translate === "") {
107107
return false;
108108
}
109-
if (is_array($toTranslate) && count($toTranslate) === 0) {
109+
if (is_array($to_translate) && count($to_translate) === 0) {
110110
return false;
111111
}
112-
if (is_array($toTranslate) || is_object($toTranslate)) {
113-
$toTranslate = json_encode($toTranslate);
112+
if (is_array($to_translate) || is_object($to_translate)) {
113+
$to_translate = json_encode($to_translate);
114114
}
115115
return [
116116
// the item id, to be used when importing
@@ -120,9 +120,9 @@ private function makeTranslatableItem($item, $output_type, $context, $translatab
120120
// the field name we want to translate
121121
"attribute_name" => $translatable_field,
122122
// the content of the field we want to translate
123-
"to_translate" => $toTranslate,
123+
"to_translate" => $to_translate,
124124
// this field remains empty since it's what the translator will use to create a translation
125-
"translation" => "",
125+
"translation" => $to_translate,
126126
// output_type is used when importing to know what we need to save
127127
"output_type"=> $output_type,
128128
// context is just there to help translators understand more of what they are doing
@@ -135,7 +135,6 @@ private function makeTranslatableItem($item, $output_type, $context, $translatab
135135
*/
136136
protected function generateCategoryEntities()
137137
{
138-
echo OutputText::info("Gathering translatable Category entities.");
139138
$attributes = Collection::make(Category::translatableAttributes());
140139
$categoriesByLang = $this->getCategories();
141140
$categoriesByLang->each(function ($categories, $language) use ($attributes) {
@@ -153,7 +152,8 @@ protected function generateCategoryEntities()
153152
* all the survey related entities base text
154153
*/
155154
$this->generateFile($items->toJson(), $language, 'categories');
156-
echo OutputText::info("Created file for categories - based on language: $language.");
155+
echo OutputText::success("Created file for categories - based on language: $language.");
156+
echo OutputText::info("Total entities to translate: " . $items->count());
157157
});
158158
}
159159

@@ -195,7 +195,6 @@ private function getPosts()
195195
*/
196196
protected function generatePostEntities()
197197
{
198-
echo OutputText::info("Gathering translatable Post entities.");
199198
$attributes = Collection::make(Post::translatableAttributes());
200199
$postsByLang = $this->getPosts();
201200
if (!$postsByLang) {
@@ -231,7 +230,8 @@ protected function generatePostEntities()
231230
* all the post related entities base text
232231
*/
233232
$this->generateFile($items->toJson(), $language, 'posts');
234-
echo OutputText::info("Created file for posts - based on language: $language.");
233+
echo OutputText::success("Created file for posts - based on language: $language.");
234+
echo OutputText::info("Total entities to translate: " . $items->count());
235235
});
236236
}
237237
/**
@@ -253,7 +253,6 @@ private function getSurveys()
253253
*/
254254
protected function makeSurveyEntities()
255255
{
256-
echo OutputText::info("Gathering translatable Surveys entities.");
257256
$surveyAttributes = Collection::make(Survey::translatableAttributes());
258257

259258
$surveysByLang = $this->getSurveys();
@@ -303,13 +302,13 @@ protected function makeSurveyEntities()
303302
});
304303
});
305304
});
306-
OutputText::info("Count" . $items->count());
307305
/**
308306
* Generates a file per each language containing
309307
* all the post related entities base text
310308
*/
311309
$this->generateFile($items->toJson(), $language, 'surveys');
312-
echo OutputText::info("Created file for surveys - based on language: $language.");
310+
echo OutputText::success("Created file for surveys - based on language: $language.");
311+
echo OutputText::info("Total entities to translate: " . $items->count());
313312
});
314313
}
315314
/**

v5/Models/Attribute.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ public static function translatableAttributes():array
7979
'label',
8080
'instructions',
8181
'default',
82-
'options',
83-
'config'
82+
'options'
8483
];
8584
}
8685
}

0 commit comments

Comments
 (0)