Skip to content

Can't iterate over yaml array of strings #614

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

Closed
4 tasks done
aidar-kz opened this issue Aug 5, 2021 · 2 comments
Closed
4 tasks done

Can't iterate over yaml array of strings #614

aidar-kz opened this issue Aug 5, 2021 · 2 comments
Labels
Status: Review Needed Request for review comments

Comments

@aidar-kz
Copy link

aidar-kz commented Aug 5, 2021

Reporting a bug?

I have an array of strings in en.yml file like this:

strings:
  - String 1
  - String 2
  - String 3

And I'm trying to display the array in a component using v-for:
<li v-for="string in t('strings')">{{ string }}</li>

But instead of displaying the array elements it iterates over the key and displays:
s
t
r
i
n
g
s

Expected behavior

v-for="$t('arrayOfString')" iterates over array of strings, not over the key

Reproduction

The issue is obvious and the provided information is enough to understand the problem?

System Info

"vue": "^3.1.5"
"vue-i18n": "^9.1.7"

Screenshot

image

Screen Shot 2021-08-05 at 8 47 28 PM

image

Additional context

No response

Validations

@aidar-kz aidar-kz added the Status: Review Needed Request for review comments label Aug 5, 2021
@PeterAlfredLee
Copy link
Member

Hi, @aidar-kz

Function t can only return a string. In your case, you should use function tm and rt, like this:

<ul>
  <li v-for="string in tm('strings')">{{ rt(string) }}</li>
</ul>

I have tested it and this can work.

See also these docs:
t
tm
rt

Hope this helps.

@aidar-kz
Copy link
Author

aidar-kz commented Aug 6, 2021

Hi, @PeterAlfredLee

Thanks a lot for your help, it now works!

Best wishes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Review Needed Request for review comments
Projects
None yet
Development

No branches or pull requests

2 participants