Replies: 2 comments 1 reply
-
Please don't use select as a shorthand switch statement. It is reserved primarily for gender choices. In your case you should just programmatically pick the right string outside of MessageFormat and order them however you like. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Ok, I settled on an array of key–value objects, which I first sort and then map through to render. The structure looks like so: const categories = [
{
key: "books",
value: intl.formatMessage({
id: "category.books",
defaultMessage: "Books"
})
},
...
].sort((a, b) => a.value < b.value ? -1 : a.value > b.value ? 1 : 0); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Imagine there's a select control with a dozen of options, which in turn are mapped over sequentially like so:
Let's assume that the options are sorted initially, i.e.
["after", ..., "eclipse"]
. This order will be preserved in English but not in other locales. It turns into a problem if the options are supposed to be sorted alphabetically regardless of the locale.To solve it, there could be another component that retrieves the options and their translations, sorts the formatted messages and then returns an array of
option
elements ready for rendering. However, I'm not exactly sure how that can be achieved.What are your suggestions and solutions? How would you tackle this problem?
I'm interested to know your thoughts.
Beta Was this translation helpful? Give feedback.
All reactions