Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translations get lost in export when there are "sub"-elements #456

Open
pekka opened this issue Mar 24, 2024 · 1 comment
Open

Translations get lost in export when there are "sub"-elements #456

pekka opened this issue Mar 24, 2024 · 1 comment

Comments

@pekka
Copy link

pekka commented Mar 24, 2024

Suppose the following translation source data:

  "question_hours_per_day" => "How many hours will you work per day?",
  "question_hours_per_day.postfix" => "hours",
   "question_hours_per_day.help" => "Enter your planned average number of work hours per day. (...) ",

Importing this into the manager works ok:

image

However, when exporting, the "root" element is lost as the dotted elements are converted into an array whose key is the root element:

 'question_hours_per_day' => 
  array (
    'postfix' => 'hours',
    'help' => 'Enter your planned average number of work hours per day. The typical work day for a Spanish full-time employee is about 8 hours. The legal maximum for employees is 9 hours per day. As an autónomo, you are usually not bound by this limitation. ',
  ),

Is having a "root" element like "question_hours_per_day" - or rather, having dotted "sub-elements" - against Laravel convention, or should this be treated as a bug?

@pekka pekka changed the title Translations break when "Root" element in translations gets lost as it becomes an array key Mar 24, 2024
@pekka pekka changed the title "Root" element in translations gets lost as it becomes an array key Translations get lost in export when there are "sub"-elements Mar 24, 2024
@pekka
Copy link
Author

pekka commented Mar 24, 2024

This is caused by the use of Arr:Set() in makeTree() in Manager.php. This is expected behaviour on Arr::Set()'s part, not sure if it should be changed in this context.

I managed to hack this by changing it so that it will always use jsonSet():

  protected function makeTree($translations, $json = false)
    {

        $array = [];
        foreach ($translations as $translation) {
               $this->jsonSet($array[$translation->locale][$translation->group], $translation->key,
                    $translation->value);

        }

        return $array;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant