Skip to content

Commit

Permalink
WIP - try to generate other pages from translations
Browse files Browse the repository at this point in the history
/about/, /contact/

It's not working yet
  • Loading branch information
matiasgarciaisaia committed Mar 18, 2020
1 parent 9ae8a92 commit 882e167
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions _plugins/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions import_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand All @@ -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]
Expand Down

0 comments on commit 882e167

Please sign in to comment.