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

Validate getTranslation function for avoiding errors #64

Closed
wants to merge 2 commits into from

Conversation

skalero01
Copy link
Contributor

#61 Validations added for avoiding errors when a translation doesnt exist

Copy link
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also provide tests to make sure that this change is needed and works?

@@ -53,7 +53,11 @@ public static function getCacheKey(string $group, string $locale): string
*/
public function getTranslation(string $locale): string
{
return $this->text[$locale] ?? $this->text[config('app.fallback_locale')];
if(isset($this->text[$locale]) && !is_array($this->text[$locale]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like to have if conditions without curly brackets as this can lead to some serious problems

@skalero01
Copy link
Contributor Author

Tests added :)

Regards

@freekmurze
Copy link
Member

I'm not going to pull this in because LanguageLine isn't really meant to hold arrays inside the language keys.

If you need this behaviour set your own model in the config key and implement the functionality in your own custom model.

@freekmurze freekmurze closed this Mar 5, 2018
@skalero01
Copy link
Contributor Author

And what about the error when you try to get a not existed translation? it is the expected behavior to get an Exception?

@freekmurze
Copy link
Member

I'd accept a PR (with tests) for that fix alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants