From: Adam Hoyle Date: Mon, 27 Sep 2021 18:30:25 +0000 (+0100) Subject: Merge branch 'master' into feature/add-communities-page X-Git-Tag: live~1447^2~33 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/06c2db433d63ebd0e5a83cb6b68a29a6ca1d5050?hp=397a03d780f8b5c5824850ae99ffdb4769dcb0c8 Merge branch 'master' into feature/add-communities-page --- diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 769fbca47..f33ce182d 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -7,7 +7,7 @@ class Ability can [:relation, :relation_history, :way, :way_history, :node, :node_history, :changeset, :note, :new_note, :query], :browse can :search, :direction - can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :preview, :copyright, :key, :id], :site + can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site can [:finish, :embed], :export can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim, :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 00b3e78da..17353fe96 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -106,6 +106,11 @@ class SiteController < ApplicationController @locale = params[:about_locale] || I18n.locale end + def communities + @locale = I18n.locale + @local_chapters = OsmCommunityIndex::LocalChapter.local_chapters_with_locale(@locale) + end + def export; end def offline; end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 192b07614..e9e88c1e0 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -50,6 +50,9 @@ + @@ -72,6 +75,7 @@ <% end %>
  • <%= link_to t("layouts.gps_traces"), traces_path, :class => "dropdown-item" %>
  • <%= link_to t("layouts.user_diaries"), diary_entries_path, :class => "dropdown-item" %>
  • +
  • <%= link_to t("layouts.communities"), communities_path, :class => "dropdown-item" %>
  • <%= link_to t("layouts.copyright"), copyright_path, :class => "dropdown-item" %>
  • <%= link_to t("layouts.help"), help_path, :class => "dropdown-item" %>
  • <%= link_to t("layouts.about"), about_path, :class => "dropdown-item" %>
  • diff --git a/app/views/site/communities.html.erb b/app/views/site/communities.html.erb new file mode 100644 index 000000000..265b26e80 --- /dev/null +++ b/app/views/site/communities.html.erb @@ -0,0 +1,19 @@ +<% content_for :heading do %> + <%= tag.h1 :lang => @locale, :dir => t("html.dir", :locale => @locale) do %> + <%= t ".title", :locale => @locale %> + <% end %> +<% end %> + +<%= tag.div :lang => @locale, :dir => t("html.dir", :locale => @locale) do %> +

    <%= t ".lede_text", :locale => @locale %>

    +

    <%= t ".local_chapters.title", :locale => @locale %>

    +

    <%= t ".local_chapters.about_text", :locale => @locale %>

    +

    <%= t ".local_chapters.list_text", :locale => @locale %>

    + +

    <%= t ".other_groups.title", :locale => @locale %>

    +

    <%= t ".other_groups.about_html", :locale => @locale %>

    +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 6869e966b..b2592c1c2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1457,6 +1457,7 @@ en: help: Help about: About copyright: Copyright + communities: Communities community: Community community_blogs: "Community Blogs" community_blogs_title: "Blogs from members of the OpenStreetMap community" @@ -2223,6 +2224,30 @@ en: Just go to the map and click the note icon: . This will add a marker to the map, which you can move by dragging. Add your message, then click save, and other mappers will investigate. + communities: + title: Communities + lede_text: | + People from all over the world contribute to or use OpenStreetMap. + Whilst some are content to participate as individuals, others have formed communities. + These groups come in a range of sizes and represent geographies from small towns to large multi-country regions. + They can also be formal or informal. + local_chapters: + title: Local Chapters + about_text: | + Local Chapters are country-level or region-level groups that have taken the formal step of + establishing not-for-profit legal entities. They represent the area's map and mappers when + dealing with local government, business, and media. They have also formed an affiliation + with the OpenStreetMap Foundation (OSMF), giving them a link to the legal and copyright + governing body. + list_text: | + So far we have the following formally established foundation Local Chapters: + other_groups: + title: Other Groups + about_html: | + There is no need to formally establish a group to the same extent as the Local Chapters. + Indeed many groups exist very sucessfully as an informal gathering of people or as a + community group. Anyone can set up or join these. Read more on the + Communities wiki page. traces: visibility: private: "Private (only shared as anonymous, unordered points)" diff --git a/config/routes.rb b/config/routes.rb index f4c19f88c..68ab163a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -147,6 +147,8 @@ OpenStreetMap::Application.routes.draw do get "/help" => "site#help" get "/about/:about_locale" => "site#about" get "/about" => "site#about" + get "/communities" => "site#communities" + get "/communities/:communities_locale" => "site#communities" get "/history" => "changesets#index" get "/history/feed" => "changesets#feed", :defaults => { :format => :atom } get "/history/comments/feed" => "changeset_comments#index", :as => :changesets_comments_feed, :defaults => { :format => "rss" } diff --git a/lib/osm_community_index/local_chapter.rb b/lib/osm_community_index/local_chapter.rb new file mode 100644 index 000000000..6b203afe8 --- /dev/null +++ b/lib/osm_community_index/local_chapter.rb @@ -0,0 +1,39 @@ +module OsmCommunityIndex + class LocalChapter + + attr_reader :id, :name, :url + + @localised_chapters = {} + + def initialize(id, name, url) + @id = id + @name = name + @url = url + end + + def self.local_chapters_with_locale(locale) + @localised_chapters[locale] ||= load_local_chapters(locale) + end + + protected + + def self.load_local_chapters(locale) + community_index = OsmCommunityIndex.community_index + localised_strings = OsmCommunityIndex.localised_strings(locale) + local_chapters = [] + community_index["resources"].each do |id, resource| + resource.each do |key, value| + next unless key == "type" && value == "osm-lc" && id != "OSMF" + + strings = resource["strings"] + name = localised_strings.dig(id, "name") || strings["name"] || strings["community"] + url = strings["url"] + local_chapters.push(LocalChapter.new(id, name, url)) + end + end + local_chapters + end + + end + +end \ No newline at end of file diff --git a/lib/osm_community_index/osm_community_index.rb b/lib/osm_community_index/osm_community_index.rb new file mode 100644 index 000000000..987f94614 --- /dev/null +++ b/lib/osm_community_index/osm_community_index.rb @@ -0,0 +1,52 @@ +module OsmCommunityIndex + class OsmCommunityIndex + require "yaml" + + @localised_strings = {} + + def self.community_index + @community_index ||= community_index_from_json + end + + def self.localised_strings(locale) + @localised_strings[locale] ||= locale_hash_from_json(locale) + end + + protected + + def self.community_index_from_json + json_file = Rails.root.join("node_modules/osm-community-index/dist/resources.json") + JSON.parse(File.read(json_file)) + end + + def self.locale_hash_from_json(locale_in) + locale = locale_in.to_s.tr("-", "_") + # try the passed in locale + json = load_locale_json(locale) + unless json.nil? + return json + end + + # now try it without it's country part (eg 'en' instead of 'en_GB') + shortened_locale = locale.split("_").first + unless shortened_locale === locale + json = load_locale_json(shortened_locale) + unless json.nil? + return json + end + end + + # if nothing else works, then return "en" + load_locale_json("en") + end + + def self.load_locale_json(locale) + json_path = Rails.root.join("node_modules/osm-community-index/i18n/#{locale}.yaml") + if File.exist?(json_path) + return YAML.safe_load(File.read(json_path))[locale] + end + nil + end + + end +end \ No newline at end of file diff --git a/package.json b/package.json index 8e4ac857e..201e433d1 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "js-cookie": "^3.0.0", "leaflet": "^1.6.0", "leaflet.locatecontrol": "^0.74.0", + "osm-community-index": "^5.1.3", "qs": "^6.9.4" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 683ca631c..d69e81356 100644 --- a/yarn.lock +++ b/yarn.lock @@ -229,6 +229,11 @@ deep-is@^0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= +diacritics@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/diacritics/-/diacritics-1.3.0.tgz#3efa87323ebb863e6696cebb0082d48ff3d6f7a1" + integrity sha1-PvqHMj67hj5mls67AILUj/PW96E= + doctrine@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961" @@ -654,6 +659,13 @@ optionator@^0.9.1: type-check "^0.4.0" word-wrap "^1.2.3" +osm-community-index@^5.1.3: + version "5.1.3" + resolved "https://registry.yarnpkg.com/osm-community-index/-/osm-community-index-5.1.3.tgz#df2bd0db2b3e43b95fa026138905dc2f3f473062" + integrity sha512-kERHt/O+QFp7DB5jH/Pkh3P1GwT3vH+lYskN7EVEBcnnsW8AIcdGpmQDlLO9IZNCbzmP7YY81wlUv8AuWKUTIg== + dependencies: + diacritics "^1.3.0" + parent-module@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"