Skip to content

Commit

Permalink
Language: new label prop
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Oct 9, 2023
1 parent 3fef058 commit 4ba7368
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
13 changes: 6 additions & 7 deletions panel/src/components/Dropdowns/LanguagesDropdown.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<template>
<div v-if="languages.length > 1" class="k-languages-dropdown">
<div
v-if="languages.length > 1"
:data-current="language.code"
class="k-languages-dropdown"
>
<k-button
:dropdown="true"
:text="code"
icon="translate"
responsive="text"
:text="language.label"
size="sm"
variant="filled"
@click="$refs.languages.toggle()"
Expand All @@ -16,9 +18,6 @@
<script>
export default {
computed: {
code() {
return this.language.code.toUpperCase();
},
language() {
return this.$panel.language;
},
Expand Down
1 change: 1 addition & 0 deletions panel/src/panel/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const defaults = () => {
code: null,
default: false,
direction: "ltr",
label: null,
name: null,
rules: null
};
Expand Down
11 changes: 11 additions & 0 deletions src/Cms/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Language
protected string $code;
protected bool $default;
protected string $direction;
protected string $label;
protected array $locale;
protected string $name;
protected array $slugs;
Expand All @@ -59,6 +60,7 @@ public function __construct(array $props)
$this->code = trim($props['code']);
$this->default = ($props['default'] ?? false) === true;
$this->direction = ($props['direction'] ?? null) === 'rtl' ? 'rtl' : 'ltr';
$this->label = trim($props['label'] ?? Str::upper($this->code));
$this->name = trim($props['name'] ?? $this->code);
$this->slugs = $props['slugs'] ?? [];
$this->smartypants = $props['smartypants'] ?? [];
Expand Down Expand Up @@ -120,6 +122,7 @@ public function clone(array $props = []): static
'code' => $this->code,
'default' => $this->default,
'direction' => $this->direction,
'label' => $this->label,
'locale' => $this->locale,
'name' => $this->name,
'slugs' => $this->slugs,
Expand Down Expand Up @@ -301,6 +304,14 @@ public function kirby(): App
return static::$kirby ??= App::instance();
}

/**
* @since 4.0.0
*/
public function label(): string
{
return $this->label;
}

/**
* Loads the language rules for provided locale code
*/
Expand Down
1 change: 1 addition & 0 deletions src/Panel/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public static function data(array $view = [], array $options = []): array
'code' => $language->code(),
'default' => $language->isDefault(),
'direction' => $language->direction(),
'label' => $language->label(),
'name' => $language->name(),
'rules' => $language->rules(),
];
Expand Down

0 comments on commit 4ba7368

Please sign in to comment.