$paths = $this->getPaths();
$translate = new \Cubist\Locale\Translate();
$translate->setExtensions($this->getExtensions());
- foreach ($paths as $path) {
- $translate->addPath(base_path() . '/' . $path);
+ foreach ($paths as $sectionLabel => $path) {
+ $translate->addPath(base_path() . '/' . $path, $sectionLabel);
}
$translate->parseFiles();
'value' => '-',
'fake' => true]);
- foreach ($translate->getStringToTranslate() as $string) {
- $key = 't_' . base64_encode($string);
+ $seenStrings = [];
- $this->addField(['name' => $key,
- 'label' => e($string),
- 'type' => 'Textarea',
- 'translatable' => true,
- 'store_in' => 'content',
- 'fake' => true]);
+ foreach ($translate->getStringToTranslate() as $sectionLabel => $strings) {
+ $toTranslate = [];
+ foreach ($strings as $string) {
+ if (isset($seenStrings[$string])) {
+ continue;
+ }
+ $toTranslate[] = $string;
+ $seenStrings[$string] = true;
+ }
+ if (!count($toTranslate)) {
+ continue;
+ }
+ if (!is_numeric($sectionLabel)) {
+ $this->addField($sectionLabel, 'FormSection', $sectionLabel);
+ }
+
+ foreach ($toTranslate as $string) {
+ $key = 't_' . base64_encode($string);
+
+ $this->addField(['name' => $key,
+ 'label' => e($string),
+ 'type' => 'Textarea',
+ 'translatable' => true,
+ 'store_in' => 'content',
+ 'fake' => true]);
+ }
}
}