From 0bd5351d7dc7d5beffd0d48a4cc940656e9aac2c Mon Sep 17 00:00:00 2001 From: Luca Degasperi Date: Tue, 29 Jun 2021 15:51:26 +0200 Subject: [PATCH 1/2] Add support for i18n content retrieval --- src/Storyblok/Client.php | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/Storyblok/Client.php b/src/Storyblok/Client.php index f5ac13a..132a1cb 100644 --- a/src/Storyblok/Client.php +++ b/src/Storyblok/Client.php @@ -53,6 +53,16 @@ class Client extends BaseClient * @var Cache */ protected $cache; + + /** + * @var string + */ + protected $language = 'default'; + + /** + * @var string + */ + protected $fallbackLanguage = 'default'; /** * @param string $apiKey @@ -83,6 +93,30 @@ public function editMode($enabled = true) $this->editModeEnabled = $enabled; return $this; } + + /** + * Set the language the story should be retrieved in + * + * @param string $language + * @return Client + */ + public function language($language = 'default') + { + $this->language = $language; + return $this; + } + + /** + * Set the fallback language the story should be retrieved in + * + * @param string $fallbackLanguage + * @return Client + */ + public function fallbackLanguage($fallbackLanguage = 'default') + { + $this->fallbackLanguage = $fallbackLanguage; + return $this; + } /** * Enables caching for 404 responses @@ -318,6 +352,14 @@ private function getStory($slug, $byUuid = false) if ($this->release) { $options['from_release'] = $this->release; } + + if ($this->language) { + $options['language'] = $this->language; + } + + if ($this->fallbackLanguage) { + $options['fallback_lang'] = $this->fallbackLanguage; + } try { $response = $this->get($key, $options); @@ -380,6 +422,14 @@ public function getStories($options = array()) if ($this->resolveRelations) { $options['resolve_relations'] = $this->resolveRelations; } + + if ($this->language) { + $options['language'] = $this->language; + } + + if ($this->fallbackLanguage) { + $options['fallback_lang'] = $this->fallbackLanguage; + } $response = $this->get($endpointUrl, $options); From 0a448f2f08f76cf0d5692712f3476d48bfed7102 Mon Sep 17 00:00:00 2001 From: Luca Degasperi Date: Tue, 29 Jun 2021 16:41:42 +0200 Subject: [PATCH 2/2] Update Client.php --- src/Storyblok/Client.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Storyblok/Client.php b/src/Storyblok/Client.php index 132a1cb..0280b82 100644 --- a/src/Storyblok/Client.php +++ b/src/Storyblok/Client.php @@ -353,12 +353,14 @@ private function getStory($slug, $byUuid = false) $options['from_release'] = $this->release; } - if ($this->language) { - $options['language'] = $this->language; - } - - if ($this->fallbackLanguage) { - $options['fallback_lang'] = $this->fallbackLanguage; + if($byUuid) { + if ($this->language) { + $options['language'] = $this->language; + } + + if ($this->fallbackLanguage) { + $options['fallback_lang'] = $this->fallbackLanguage; + } } try {