Skip to content

Commit

Permalink
add multilang setting (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
schliflo authored Feb 23, 2021
1 parent a69208a commit f01a7e5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ form:
validate:
type: bool

multilang_enabled:
type: toggle
label: PLUGIN_SITEMAP.MULTILANG_ENABLED
help: PLUGIN_SITEMAP.MULTILANG_ENABLED_HELP
highlight: 1
default: 1
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool

ignore_external:
type: toggle
label: PLUGIN_SITEMAP.IGNORE_EXTERNAL
Expand Down
4 changes: 4 additions & 0 deletions languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ en:
IGNORE_REDIRECT_HELP: 'Ignores pages that have a custom "redirect" entry in the header'
URLSET: 'URLSet'
URLSET_HELP: 'The URLSet XML Namespace, don''t change this!'
MULTILANG_ENABLED: 'Multi-Lang Features'
MULTILANG_ENABLED_HELP: 'Enables support for multilanguage features'
INCLUDE_CHANGEFREQ: 'Include Change Frequency'
INCLUDE_PRIORITY: 'Include Priority'
SHORT_DATE_FORMAT: 'Short Date Format'
Expand Down Expand Up @@ -111,6 +113,8 @@ de:
ADDITIONS_HELP: 'Füge externe URLs zur Sitemap hinzu'
LOCATION: 'Seiten Pfad'
LASTMOD: 'Letzte Änderung e.g. 2017-04-06'
MULTILANG_ENABLED: 'Mehrsprachigkeit'
MULTILANG_ENABLED_HELP: 'Aktiviert Funktionen zur Mehrsprachigkeit'

zh:
PLUGIN_SITEMAP:
Expand Down
5 changes: 4 additions & 1 deletion sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SitemapPlugin extends Plugin

protected $multilang_skiplang_prefix = null;
protected $multilang_include_fallbacks = false;
protected $multilang_enabled = true;
protected $datetime_format = null;
protected $include_change_freq = true;
protected $default_change_freq = null;
Expand Down Expand Up @@ -102,11 +103,13 @@ public function onPagesInitialized()
$this->sitemap = $cache->fetch($cache_id);

if ($this->sitemap === false) {
$this->multilang_enabled = $this->config->get('plugins.sitemap.multilang_enabled');

/** @var Language $language */
$language = $this->grav['language'];
$default_lang = $language->getDefault() ?: 'en';
$active_lang = $language->getActive() ?? $default_lang;
$languages = $language->enabled() ? $language->getLanguages() : [$default_lang];
$languages = $this->multilang_enabled && $language->enabled() ? $language->getLanguages() : [$default_lang];

$this->multilang_skiplang_prefix = $this->config->get('system.languages.include_default_lang') ? '' : $language->getDefault();
$this->multilang_include_fallbacks = $this->config->get('system.languages.pages_fallback_only') || !empty($this->config->get('system.languages.content_fallback'));
Expand Down
3 changes: 2 additions & 1 deletion sitemap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ include_changefreq: true
changefreq: daily
include_priority: true
priority: !!float 1
additions: []
additions: []
multilang_enabled: true

0 comments on commit f01a7e5

Please sign in to comment.