Skip to content

Commit

Permalink
Merge pull request #217 from CDRH/dev
Browse files Browse the repository at this point in the history
fix language config problem
  • Loading branch information
techgique authored Nov 17, 2020
2 parents 79f643e + 724c032 commit 3658b61
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 19 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Fixed
- bug with locales yaml creation
- es locale file will be copied into app if Spanish requested
- thumbnail size in `public.yml` requires quotation marks for newer psyche yaml gem

### Added
- partials for browse, browse_facet, index, and search_preset header content for easier overriding
Expand All @@ -44,8 +46,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- `language` (head)

### Changed
- `ALL_LANGUAGES` setting changed back to `languages`
- language documentation clarified and expanded
- references to `APP_OPTS["languages"]` changed to use `all_languages`

### Migration
- rename `languages` and `ALL_LANGUAGES` to `all_languages` in `public.yml` file

## [v3.1.0](https://github.com/CDRH/orchid/compare/v3.0.3...v3.1.0) - search_preset, improved section links, and misc display

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/orchid/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def locale
end

def locale_link(lang_code)
locales = APP_OPTS["languages"].split("|")
.reject { |l| l == APP_OPTS["language_default"] }.join("|")
locales = APP_OPTS["all_languages"].split("|")
.reject { |l| l == APP_OPTS["all_language_default"] }.join("|")
url = request.fullpath

if lang_code == APP_OPTS["language_default"]
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/body/_languages.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% langs = APP_OPTS["languages"] %>
<% langs = APP_OPTS["all_languages"] %>

<% if langs.present? && langs[/\|/] %>
<div class="language_link btn-group" role="group" aria-label="language choice">
Expand Down
5 changes: 3 additions & 2 deletions app/views/layouts/head/_language.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%# links for alternate language pages %>
<% if APP_OPTS["languages"].present? && APP_OPTS["languages"][/\|/] %>
<% APP_OPTS["languages"].split("|").each do |lang_code| %>
<% langs = APP_OPTS["all_languages"] %>
<% if langs.present? && langs[/\|/] %>
<% langs.split("|").each do |lang_code| %>
<%# if this is the currently selected language
then no alternative link is needed for it %>
<% next if lang_code == I18n.locale.to_s %>
Expand Down
30 changes: 20 additions & 10 deletions lib/generators/setup_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ def copy_configs_and_locales
"#{@new_app}/config/private.yml")
FileUtils.cp("#{@this_app}/lib/generators/templates/public.yml",
"#{@new_app}/config/public.yml")
# en locale file is always copied by default
FileUtils.cp("#{@this_app}/config/locales/en.yml",
"#{@new_app}/config/locales/en.yml")

puts "Please enter the following for initial app customization"

Expand All @@ -87,12 +84,11 @@ def copy_configs_and_locales

langs = prompt_for_value("All languages, including primary (separated with a pipe: en|es|cz)",
"en")
config_set("public", "languages", langs)
config_set("public", "all_languages", langs)

all_langs = langs.blank? ? [] : langs.split("|")
all_langs.each do |lang|
# for each language which is not english, create a locale file
next if lang == "en"
# create a locale file for each specified language
copy_locale(lang)
end

Expand All @@ -111,7 +107,7 @@ def copy_configs_and_locales
# pre-made translations. Users will need to supply their own values for the
# strings in the file.

Array(langs).each do |lang|
all_langs.each do |lang|
config_set("locales/#{lang}", "project_name", project_name,
uncomment: true)
config_set("locales/#{lang}", "project_shortname", project_shortname,
Expand All @@ -129,6 +125,10 @@ def copy_configs_and_locales
config_set("public", "media_server_dir", answer)

answer = prompt_for_value("Thumbnail Size (default: !200,200)", "!200,200")
# due to the exclamation mark, this needs to be surrounded in quotation marks
if !answer[/^".*"$/]
answer = "\"#{answer}\""
end
config_set("public", "thumbnail_size", answer)

# private config customization
Expand Down Expand Up @@ -172,9 +172,19 @@ def copy_initializer
end

def copy_locale(lang)
FileUtils.cp("#{@this_app}/config/locales/en.yml",
"#{@new_app}/config/locales/#{lang}.yml")
gsub_file "#{@new_app}/config/locales/#{lang}.yml", /^en:$/, "#{lang}:"
supported_langs = [ "en", "es" ]

if supported_langs.include?(lang)
# by default, copy the locale files of any languages Orchid supports over
FileUtils.cp("#{@this_app}/config/locales/#{lang}.yml",
"#{@new_app}/config/locales/#{lang}.yml")
else
# for non-supported languages, copy the english template with the expectation
# that it will be translated into the correct language
FileUtils.cp("#{@this_app}/config/locales/en.yml",
"#{@new_app}/config/locales/#{lang}.yml")
gsub_file "#{@new_app}/config/locales/#{lang}.yml", /^en:$/, "#{lang}:"
end
end

def copy_remaining_templates
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/public.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ default: &default
# defaults to "en" (english) if no default language set
language_default: en
# pipe delineated codes for all languages, e.g. "en|es|cz"
ALL_LANGUAGES: en
all_languages: en
# for application title settings, please alter the files in config/locales

# IMAGES
Expand Down
4 changes: 2 additions & 2 deletions lib/orchid/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def draw(section: "", routes: [], scope: "")

# If multiple languages, constrain locale to non-default language codes
locales = nil
if defined?(APP_OPTS) && APP_OPTS["languages"].present?
other_languages = APP_OPTS["languages"].split("|")
if defined?(APP_OPTS) && APP_OPTS["all_languages"].present?
other_languages = APP_OPTS["all_languages"].split("|")
.reject { |l| l == APP_OPTS["language_default"] }

if other_languages.present?
Expand Down

0 comments on commit 3658b61

Please sign in to comment.