質問

How is it possible to find all the available locales from a template in SailsJS.

I want to make a dropdown menu in my layout.ejs with all the possible languages declared in the /config/i18n but I don't want to specify the supported languages in another file.

I don't know if it's possible, I've seen only solutions on Rails but I'm stuck on Sails... I haven't found availableLocales field or anything similar.

役に立ちましたか?

解決

You can access the available locales in your controller via sails.config.i18n.locales. You could then send that array down to your view as a local:

res.view('myView', {locales: sails.config.i18n.locales});

and in your view, loop through them with something like:

<select name="locale">
<% locales.forEach(function(locale) { %>
    <option value="<%=locale%>"><%=locale%></option>
<% }); %>
</select>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top