Skip to content

Commit

Permalink
feat: importFrom secondary languages
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Jun 11, 2024
1 parent 780af0b commit 51a6eeb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/classes/ContentTranslator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Kirby\Cms\App;
use Kirby\Cms\File;
use Kirby\Cms\ModelWithContent;
use Kirby\Cms\Page;
use Kirby\Cms\Site;
use Kirby\Data\Data;
Expand Down Expand Up @@ -62,7 +63,7 @@ public static function translateText(string $text, string $targetLanguage, strin
return $deepL->translate($text, $targetLanguage, $sourceLanguage);
}

public static function resolveModelFields(Site|Page $model): array
public static function resolveModelFields(ModelWithContent $model): array
{
$fields = $model->blueprint()->fields();
$lang = $model->kirby()->languageCode();
Expand Down
33 changes: 20 additions & 13 deletions src/extensions/sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,38 @@
'content-translator' => [
'props' => [
'label' => fn ($label = null) => I18n::translate($label, $label),
'confirm' => fn ($confirm = true) => $confirm === true,
'import' => fn ($import = true) => $import === true,
'importFrom' => function ($importFrom = null) {
if ($importFrom === 'all') {
return 'all';
}

return $importFrom;
},
'title' => fn ($title = false) => $title === true,
'slug' => fn ($slug = false) => $slug === true,
'confirm' => fn ($confirm = true) => $confirm === true,
'fieldTypes' => function ($fieldTypes = null) {
if (is_array($fieldTypes)) {
return array_map('strtolower', $fieldTypes);
if (!is_array($fieldTypes)) {
return null;
}

return $fieldTypes;
return array_map('strtolower', $fieldTypes);
},
'includeFields' => function ($includeFields = null) {
if (is_array($includeFields)) {
return array_map('strtolower', $includeFields);
if (!is_array($includeFields)) {
return null;
}

return $includeFields;
return array_map('strtolower', $includeFields);
},
'excludeFields' => function ($excludeFields = null) {
if (is_array($excludeFields)) {
return array_map('strtolower', $excludeFields);
if (!is_array($excludeFields)) {
return null;
}

return $excludeFields;
},
'title' => fn ($title = false) => $title === true,
'slug' => fn ($slug = false) => $slug === true
return array_map('strtolower', $excludeFields);
}
],
'computed' => [
'fields' => function () {
Expand Down
12 changes: 7 additions & 5 deletions src/panel/components/ContentTranslator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const isOnline = navigator.onLine;
// Section props
const label = ref();
const confirm = ref(true);
const importable = ref(true);
const allowImport = ref(true);
const importFrom = ref();
const fieldTypes = ref([]);
const includeFields = ref([]);
const excludeFields = ref([]);
Expand Down Expand Up @@ -63,7 +64,8 @@ const currentContent = computed(() => store.getters["content/values"]());
label.value =
t(response.label) || panel.t("johannschopplich.content-translator.label");
confirm.value = response.confirm ?? response.config.confirm;
importable.value = response.import ?? response.config.import;
allowImport.value = response.import ?? response.config.import;
importFrom.value = response.importFrom ?? response.config.importFrom;
fieldTypes.value = response.fieldTypes ??
response.config.fieldTypes ?? [
"blocks",
Expand Down Expand Up @@ -244,13 +246,13 @@ function openModal(text, callback) {
configuration.
</k-text>
</k-box>
<k-box v-else-if="config.allowDefaultLanguageOverwrite" theme="none">
<k-box v-else-if="importFrom === 'all'" theme="none">
<k-button-group layout="collapsed">
<k-button
v-for="language in panel.languages.filter(
(language) => language.code !== panel.language.code,
)"
v-show="importable"
v-show="allowImport"
:key="language.code"
icon="import"
size="sm"
Expand Down Expand Up @@ -296,7 +298,7 @@ function openModal(text, callback) {
<k-box theme="none">
<k-button-group layout="collapsed">
<k-button
v-show="importable"
v-show="allowImport"
:disabled="panel.language.default"
icon="import"
size="sm"
Expand Down

0 comments on commit 51a6eeb

Please sign in to comment.