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

Minh Nguyễn notifications at github.com
Tue May 13 07:33:25 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>

Do we need to generate this menu statically? If we can rely on JavaScript to generate the labels, then [`Intl.DisplayNames`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) would save our translators the burden of translating all these language names yet again. (Or you could use the same API to preserve each language’s name for itself.) For example, [here’s how OpenStreetMap Americana](https://github.com/osm-americana/openstreetmap-americana/blob/7fe7232d102e309e2398c719eedcc294220c39cc/src/js/language_label.js#L39-L114) generates its language selector. If JavaScript is disabled or the browser doesn’t support this API, we could fall back to ISO 639 codes or a text field.

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

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


More information about the rails-dev mailing list