0

I want to localize my app, but I got a problem:

If I call the trans function like this: {{ __('permission.addUser') }}, the output is

Add new user

If I call {{$permissions[13]}} the output is

addUser

But if I mix them: {{ __('permission.$permission[13]') }}, the output is

permission.$permissions[13]

What's missing? What I did wrong?

3

2 Answers 2

1

I know you already have your answer, but in PHP, you can use double quotes to insert variables into strings, for example

echo "permission.$permissions_13"

will output correctly. If you want to use arrays or objects, you should wrap them in {}.

__("permission.{$permissions[13]}")

Remember, double quotes

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer. In "flat php" I use the double quotes in a lot of situations, but laravel-blade somewhy can't "eat" them. It drop's this error: > Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Oh, I had no idea. Weird. Then yes, your solution sounds correct, string concat :)
0

Oops, I wanted to use my variable as a string.

The solution is {{ __('permission.' . $permissions[13]) }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.