mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 01:36:13 +00:00
Add script used to update translation templates
This commit is contained in:
parent
cb443a8dda
commit
9b62dc6f83
2 changed files with 41 additions and 2 deletions
|
@ -28,9 +28,9 @@ Installing dependencies on older Ubuntu and Debian distributions
|
|||
|
||||
### Import translations
|
||||
|
||||
**Update translations**: You can overwrite each language files in _translations by their updated version from Transifex. You should make sure that each .html files (in _layouts, _templates) don't serve outdated content for those languages. You should also make sure that no url has been changed by translators. If one page has been replaced or moved, a redirection can be added in _config.yml.
|
||||
**Update translations**: You can update the relevant language file in \_translations/ and run ./\_contrib/updatetx.rb to update layouts and templates for this language. You should also make sure that no url has been changed by translators. If one page has been replaced or moved, a redirection can be added in \_config.yml.
|
||||
|
||||
**Add a new language**: You can put the language file from Transifex in _translations and add the language in _config.yml in the right display order for the language bar. Make sure to review all pages and check all links.
|
||||
**Add a new language**: You can put the language file from Transifex in \_translations and add the language in \_config.yml in the right display order for the language bar. Make sure to review all pages and check all links.
|
||||
|
||||
### Update english strings
|
||||
|
||||
|
|
39
_contrib/updatetx.rb
Executable file
39
_contrib/updatetx.rb
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
#Drop outdated fallback HTML code in all layouts for specified language.
|
||||
#Example: ./_contrib/updatetx.rb
|
||||
|
||||
def prompt(*args)
|
||||
print(*args)
|
||||
gets
|
||||
end
|
||||
|
||||
lang = prompt "Language code: "
|
||||
lang = lang.gsub(/[^a-z]/,'')
|
||||
|
||||
if !File.exist?('_translations/' + lang + '.yml')
|
||||
print "Wrong language code. \n"
|
||||
exit
|
||||
end
|
||||
|
||||
dirs = [ '_templates', '_layouts' ]
|
||||
|
||||
dirs.each do |dir|
|
||||
Dir.foreach(dir) do |file|
|
||||
next if file == '.' or file == '..'
|
||||
contents = File.read(dir + '/' + file)
|
||||
# Drop HTML code applied to current language only ( until next {% when / else / endcase %} statement )
|
||||
contents.gsub!(Regexp.new("{% when '" + lang + "' %}((?!{% endcase %})(?!{% else %}).)*?{% when", Regexp::MULTILINE),'{% when')
|
||||
contents.gsub!(Regexp.new("{% when '" + lang + "' %}((?!{% endcase %}).)*?{% else %}", Regexp::MULTILINE),'{% else %}')
|
||||
contents.gsub!(Regexp.new("{% when '" + lang + "' %}.*?{% endcase %}", Regexp::MULTILINE),'{% endcase %}')
|
||||
# Drop complete {% case / endcase %} statements when not used by any language anymore
|
||||
contents.gsub!(Regexp.new("{% case page.lang %}(((?!{% when ).)*?){% else %}(.*?){% endcase %}", Regexp::MULTILINE),'\1 \3')
|
||||
contents.gsub!(Regexp.new("{% case page.lang %}(((?!{% when ).)*?){% endcase %}", Regexp::MULTILINE),'\1')
|
||||
# Drop language in statements applied to many languages ( e.g. {% when 'ar' or 'fr' .. %} )
|
||||
contents.gsub!(Regexp.new("{% when '" + lang + "' or (.*?) %}"),'{% when \1 %}')
|
||||
contents.gsub!(Regexp.new("{% when (.*?) or '" + lang + "' (.*?) %}"),'{% when \1 \2 %}')
|
||||
File.open(dir + '/' + file, 'w') do |file|
|
||||
file.write(contents)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue