[openstreetmap/openstreetmap-website] Add locale selector (PR #5201)

Minh Nguyễn notifications at github.com
Tue May 13 15:00:17 UTC 2025


@1ec5 commented on this pull request.



> +    <select role="button" class="p-0 position-absolute top-0 start-0 w-100 h-100 language-change-trigger text-transparent bg-transparent <%= classes %>">
+      <% Locale.available
+               .select { |locale| I18n.exists? "shared.language_selector.#{locale}" }
+               .sort_by { |locale| t(".#{locale}") }
+               .each do |locale| %>
+        <option class="form-select" value="<%= locale.to_s %>" <%= "selected" if I18n.locale.to_s == locale.to_s %>><%= t(".#{locale}") %></option>
+      <% end %>
+    </select>

[`Intl.DisplayNames.prototype.of()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames/of) returns undefined if the language code is unrecognized, so we could fall back to the raw code. It only throws an exception on a malformed language code. But if we already have a string that we can access at build time, that would be good too. In that case, we wouldn’t need all those added lines in the YAML file, one for each language…

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5201#discussion_r2087048210
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/5201/review/2837146028 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250513/969ad660/attachment.htm>


More information about the rails-dev mailing list