Skip to content

Commit

Permalink
Merge pull request #27 from lucadegasperi/master
Browse files Browse the repository at this point in the history
Add support for i18n content retrieval
  • Loading branch information
christianzoppi authored Jan 13, 2022
2 parents 1b93e7d + 5a21ff4 commit e3a892f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Storyblok/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -333,6 +367,16 @@ private function getStory($slug, $byUuid = false)
$options['from_release'] = $this->release;
}

if($byUuid) {
if ($this->language) {
$options['language'] = $this->language;
}

if ($this->fallbackLanguage) {
$options['fallback_lang'] = $this->fallbackLanguage;
}
}

try {
$response = $this->get($key, $options);
$this->_save($response, $cachekey, $this->getVersion());
Expand Down Expand Up @@ -386,6 +430,14 @@ public function getStories($options = array())
$options['resolve_relations'] = $this->resolveRelations;
}

if ($this->language) {
$options['language'] = $this->language;
}

if ($this->fallbackLanguage) {
$options['fallback_lang'] = $this->fallbackLanguage;
}

if ($this->resolveLinks) {
$options['resolve_links'] = $this->resolveLinks;
}
Expand Down

0 comments on commit e3a892f

Please sign in to comment.