From 882e1677f1a823bfe64d2ee7a7cf000a36692639 Mon Sep 17 00:00:00 2001 From: Matias Garcia Isaia Date: Mon, 16 Mar 2020 18:23:27 -0300 Subject: [PATCH] WIP - try to generate other pages from translations /about/, /contact/ It's not working yet --- _plugins/common.rb | 9 +++++++++ import_language.rb | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/_plugins/common.rb b/_plugins/common.rb index c40fb26ce..33d0058e1 100644 --- a/_plugins/common.rb +++ b/_plugins/common.rb @@ -12,3 +12,12 @@ def key_from_page_filename(name) return $1 end end + +def key_from_top_level_file(name) + basename = File.basename(name) + if basename =~ /(.+)-(\w\w).md/ + return $1 + else + raise "#{basename} doesn't match the \"some-page-en.md\" name format (in #{name})" + end +end diff --git a/import_language.rb b/import_language.rb index 9cce954f5..642deed69 100644 --- a/import_language.rb +++ b/import_language.rb @@ -18,6 +18,11 @@ def language_dir(lang) SECTIONS_TO_FILES[key_from_filename(filename)] = filename } +TOP_LEVEL_PAGES = {} +Dir["*-en.md"].sort!.each { |filename| + TOP_LEVEL_PAGES[key_from_top_level_file(filename)] = filename +} + def generate_content(translations_lang, translations_file) translations = JSON.parse(File.open(translations_file, 'r:UTF-8') { |f| f.read }) @@ -31,6 +36,17 @@ def generate_content(translations_lang, translations_file) file.puts translations[section] } end + + TOP_LEVEL_PAGES.each do |page, source_file| + puts "source_file: #{source_file}" + puts "page: #{page}" + puts "tranlsations_lang: #{translations_lang}" + translated_file = source_file.sub(/-en.md$/, "-#{translations_lang}.md") + puts "Translated_file: #{translated_file}" + File.open(translated_file, "w:UTF-8") { |file| + file.puts translations[page] + } + end end LOKALISE_TOKEN = ARGV[0]