Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable redirect to outdated translations #1828

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions _plugins/translation_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,27 @@ module Jekyll
# Outputs HTML.
module TranslationStatus

LANGS = %w{en de es fr id it ja ko ru vi zh_cn zh_tw}
START_DATE = '2013-04-01'
LANGS_MAP = {
"en" => nil,
# "bg" => "bg",
"de" => "de",
"es" => "es",
"fr" => "fr",
"id" => "id",
"it" => "it",
"ja" => "ja",
"ko" => "ko",
# "pl" => "pl",
# "pt" => "pt",
"ru" => "ru",
# "tr" => "tr",
"vi" => "vi",
"zh_cn" => "zh-CN",
"zh_tw" => "zh-TW",
}
LANGS = LANGS_MAP.keys

START_DATE = Time.utc(2013, 4, 1)

OK_CHAR = '✓'
MISSING_CHAR = '' # '✗'
Expand All @@ -19,7 +38,7 @@ module TranslationStatus
TEMPLATE =<<-EOF.gsub(/^ /, '')
<p>
Posts with missing translations: <%= posts.size.to_s %><br>
Start date: <%= START_DATE %><br>
Start date: <%= START_DATE.strftime('%Y-%m-%d') %><br>
Ignored languages: <%= ignored %>
</p>

Expand Down Expand Up @@ -96,7 +115,7 @@ def remove_completed_posts
end

def too_old(date)
date.strftime("%Y-%m-%d") < START_DATE
date < START_DATE
end

def table_header
Expand Down Expand Up @@ -129,7 +148,32 @@ def render(context)
ERB.new(TEMPLATE, nil, '-').result(binding)
end
end

class LanguagesJson < Liquid::Tag
def render(context)
categories = context.registers[:site].categories

newest_post_date = Hash.new(START_DATE)

LANGS.each do |lang|
categories[lang].each do |post|
if newest_post_date[lang] < post.date
newest_post_date[lang] = post.date
end
end
end

about_6_months_ago = Time.now - 60*60*24*30*6
newest_post_date.delete("en")
newest_post_date.delete_if {|_lang, date| date < about_6_months_ago }
languages = newest_post_date.keys.map do |lang|
%Q("#{LANGS_MAP[lang]}": "#{lang}")
end
"{#{languages.join(',')}}"
end
end
end
end

Liquid::Template.register_tag('translation_status', Jekyll::TranslationStatus::Tag)
Liquid::Template.register_tag('languages_json', Jekyll::TranslationStatus::LanguagesJson)
21 changes: 3 additions & 18 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
---
---
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Ruby Programming Language</title>
<script type="text/javascript">
var languages = {
"bg": "bg",
"de": "de",
"es": "es",
"fr": "fr",
"id": "id",
"it": "it",
"ja": "ja",
"ko": "ko",
"pl": "pl",
"pt": "pt",
"ru": "ru",
"tr": "tr",
"vi": "vi",
"zh-CN": "zh_cn",
"zh-TW": "zh_tw"
};

var languages = {% languages_json %};
var code = window.navigator.language || window.navigator.userLanguage || "en";
if (code.substr(0,2) !== "zh") { code = code.substr(0,2); }

Expand Down