Skip to content

Commit

Permalink
Refactors language translation link settings
Browse files Browse the repository at this point in the history
- Strips whitespace around language code setting so any amount of
spacing can be introduced into the settings and the app won’t silently
not configure the language code URL properly.
- Adds ability to remove all language links and the app won’t break.
Ties into #483.
- Edits language links code comments to be consistent with other
settings in the settings file and adds a space after the colon in the
settings to be consistent with Ruby style guide key/value styling.
  • Loading branch information
anselmbradford committed Aug 26, 2014
1 parent 184af84 commit 780de8c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/helpers/language_links_helper.rb
@@ -1,7 +1,7 @@
module LanguageLinksHelper
def language_link_tag(language_plus_code)
language = language_plus_code.split(':').first
code = language_plus_code.split(':').second
code = language_plus_code.split(':').second.strip!

link_to_unless(@current_lang == code, language, "?translate=#{code}", lang: code, class: 'notranslate button-small') do |language_text|
content_tag(:a, language_text, lang: code, class: 'translate-active button-small')
Expand Down
11 changes: 6 additions & 5 deletions app/views/component/search/_languages.html.haml
@@ -1,5 +1,6 @@
%section#language-box
%ul
- SETTINGS[:language_links].each do |language_plus_code|
%li
= language_link_tag language_plus_code
- if SETTINGS[:language_links].present?
%section#language-box
%ul
- SETTINGS[:language_links].each do |language_plus_code|
%li
= language_link_tag language_plus_code
23 changes: 12 additions & 11 deletions config/settings.example.yml
Expand Up @@ -211,26 +211,27 @@ info_box_terms:

###################################################################
#
# LANGUAGE LINKS SETTINGS
# LANGUAGE TRANSLATION LINKS SETTINGS
#
###################################################################

# This represents the 6 most common languages in your community.
# This represents the most common languages in your community.
# The languages will appear at the top of the home page, and
# clicking on each language will translate the text on the entire
# site into that language using Google Translate.
# The format should be 'Language:code', as shown below.
# The format should be 'Language: code', as shown below.
# To see a list of all supported languages and codes, read the
# "Language reference" section in the Google Translate documentation:
# https://developers.google.com/translate/v2/using_rest

# https://developers.google.com/translate/v2/using_rest#language-params
# If you do not wish to include any language translation links,
# comment out or delete all of the language settings shown.
language_links:
- 'English:en'
- 'Español:es'
- 'Tagalog:tl'
- '中文:zh-CN'
- 'العربية:ar'
- 'Русский:ru'
- 'English: en'
- 'Español: es'
- 'Tagalog: tl'
- '中文: zh-CN'
- 'العربية: ar'
- 'Русский: ru'

######################
#
Expand Down
35 changes: 18 additions & 17 deletions config/settings.yml
Expand Up @@ -211,26 +211,27 @@ info_box_terms:

###################################################################
#
# LANGUAGE LINKS SETTINGS
# LANGUAGE TRANSLATION LINKS SETTINGS
#
###################################################################

# This represents the 6 most common languages in your community.
# This represents the most common languages in your community.
# The languages will appear at the top of the home page, and
# clicking on each language will translate the text on the entire
# site into that language using Google Translate.
# The format should be 'Language:code', as shown below.
# The format should be 'Language: code', as shown below.
# To see a list of all supported languages and codes, read the
# "Language reference" section in the Google Translate documentation:
# https://developers.google.com/translate/v2/using_rest

# https://developers.google.com/translate/v2/using_rest#language-params
# If you do not wish to include any language translation links,
# comment out or delete all of the language settings shown.
language_links:
- 'English:en'
- 'Español:es'
- 'Tagalog:tl'
- '中文:zh-CN'
- 'العربية:ar'
- 'Русский:ru'
- 'English: en'
- 'Español: es'
- 'Tagalog: tl'
- '中文: zh-CN'
- 'العربية: ar'
- 'Русский: ru'

######################
#
Expand Down Expand Up @@ -306,11 +307,11 @@ test:
custom: component/info_box/example_custom_template

language_links:
- 'English:en'
- 'Español:es'
- 'Tagalog:tl'
- '中文:zh-CN'
- 'العربية:ar'
- 'Русский:ru'
- 'English: en'
- 'Español: es'
- 'Tagalog: tl'
- '中文: zh-CN'
- 'العربية: ar'
- 'Русский: ru'

site_title: Ohana Web Search

0 comments on commit 780de8c

Please sign in to comment.