Updating choose-your-wallet. Adds wallets page generator with translations.

This commit is contained in:
Igor Kuzmenko 2017-07-18 15:21:36 +02:00
parent c68f7ed7b5
commit d206471809
3 changed files with 46 additions and 108 deletions

View file

@ -6,7 +6,7 @@ require 'yaml'
module Jekyll
class WalletPage < Page
def initialize(site, base, dir, wallet, platform, os)
def initialize(site, base, dir, wallet, platform, os, lang)
@site = site
@base = base
@dir = dir
@ -18,6 +18,7 @@ module Jekyll
self.data['platform'] = platform
self.data['os'] = os
self.data['id'] = ['wallets', platform['name'], os['name'], wallet['id']].join('-')
self.data['lang'] = lang
end
end
@ -25,27 +26,61 @@ module Jekyll
safe true
def generate(site)
# Get the collection of wallets from _wallets
walletsCol = site.collections['wallets'];
# Output dir
# TODO: Make this configurable and "translatable"
walletsDir = 'wallets'
# Loading translations.
# Copy-paste from _plugins/templates.rb
locs = {}
enabled = ENV['ENABLED_LANGS'];
enabled = enabled.split(' ') if !enabled.nil?
Dir.foreach('_translations') do |file|
next if file == '.' or file == '..' or file == 'COPYING'
lang = file.split('.')[0]
# Ignore language if it's disabled
if lang != 'en' and !enabled.nil? and !enabled.include?(lang)
puts('Lang ' + lang + ' disabled')
next
end
locs[lang] = YAML.load_file("_translations/"+file)[lang]
end
puts('----- Generating wallet pages -----')
# Getting information about each found wallet
walletsCol.docs.each do |doc|
file = doc.path
wallet = YAML.load_file(file)
walletPlatforms = wallet['platform']
puts('---------------------')
puts(wallet['id'])
puts(wallet['id'] + ' is loaded. Generating pages...')
# Going through all available combinations of
# platforms and OSes
walletPlatforms.each do |platform|
platform['os'].each do |os|
# This allows generation only of valid wallet pages
if platform['name']
locs.each do |lang,value|
dir = File.join(platform['name'], os['name'], wallet['id'])
site.pages << WalletPage.new(site, site.source, File.join('en', walletsDir, dir), wallet, platform, os)
site.pages << WalletPage.new(site, site.source, File.join(lang, walletsDir, dir), wallet, platform, os, lang)
end
end
end
end
puts(wallet['id'] + ' is processed.')
end
puts('----- Wallet pages generated -----')
end
end