Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-language View #97

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,16 @@ public function renderFile(string $viewFile, array $parameters = [], ?ViewContex
$viewFile = $this->theme->applyTo($viewFile);
}

if (is_file($viewFile)) {
$viewFile = $this->localize($viewFile);
} else {
if (!is_file($viewFile)) {
throw new ViewNotFoundException("The view file does not exist: $viewFile");
}

$contextLanguage = null;
if ($context !== null) {
$contextLanguage = $context->getLanguage();
}
$viewFile = $this->localize($viewFile, $contextLanguage);

$oldContext = $this->context;
if ($context !== null) {
$this->context = $context;
Expand Down
10 changes: 8 additions & 2 deletions src/ViewContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
/**
* ViewContextInterface is the interface that should implemented by classes who want to support relative view names.
*
* The method {@see ViewContextInterface::getViewPath()} should be implemented to return the view path that may be prefixed to a relative view name.
* The method {@see ViewContextInterface::getViewPath()} should be implemented to return the view path that may
* be prefixed to a relative view name.
*/
interface ViewContextInterface
{
/**
* @return string the view path that may be prefixed to a relative view name.
* @return string The view path that may be prefixed to a relative view name.
*/
public function getViewPath(): string;

/**
* @return string The language to use when choosing a view.
*/
public function getLanguage(): ?string;
}