many important fixes

This commit is contained in:
2020-02-29 11:43:00 -05:00
parent 2149345d3d
commit 73c207c324
28 changed files with 1463 additions and 242 deletions
+78 -2
View File
@@ -2,9 +2,18 @@
#require 'pathname'
#require 'active_support/all'
#require 'yaml'
#require 'pry'
require 'pry'
#$root = Pathname.new File.expand_path('../../', __FILE__)
class UserApp
def write_output(locale)
out_file = File.open "#{ENV['MOZO_PATH_USER']}/app/i18n/#{locale}.coffee", 'w+'
out_file.puts "window.$translations ||= {}"
out_file.puts "$translations.#{locale} ="
Proc.new do |output|
out_file.puts output
end
end
def path
Pathname.new File.expand_path('../../../mozo-user', __FILE__)
end
@@ -33,10 +42,77 @@ class UserApp
end
def write_translations
translations = all_translations # caching
File.write "translations.yml", translations.to_yaml
HashToCS.convert(translations['en'], 2, write_output('en'))
HashToCS.convert(translations['nl'], 2, write_output('nl'))
return
File.open path.join('vendor/i18n/translations.js'), 'w+' do |f|
f.puts "$translations = #{JSON.pretty_generate all_translations}"
f.puts "$translations = #{JSON.pretty_generate translations}"
end
end
end
# Franc Paul
#
# convert a ruby hash to coffescript object
##
module HashToCS
=begin
usage:
proc = Proc.new do |output|
coffee_script_file.puts output
end
HashToCs.convert(ruby_hash, 2, proc)
=end
defaultProc = Proc.new do |output|
print output
end
#input is a Ruby hash
#spaces is an integer count of spaces to be used as a prefix string for whitespace significance
#proc acts on the output
def HashToCS.convert(input, spaces=0, proc=defaultProc)
spaces = " " * spaces
case input
when String
q = if input =~ /\n/
'"""'
else
'"'
end
proc.call spaces + q + input + q + "\n"
when Array
proc.call spaces + "[\n"
input.each do |a|
convert(a, spaces.size + 2, proc)
end
proc.call spaces + "]\n"
when Hash
#proc.call spaces + "{\n"
input.each do |k, v|
key_string = k =~ /\W/ ? "\"#{k}\"" : "#{k}"
if v.is_a?(String)
if v =~ /\n/
proc.call spaces + "#{key_string}: \"\"\"\n#{v}\"\"\"\n"
else
proc.call spaces + "#{key_string}: \"#{v}\"\n"
end
else
proc.call spaces + "#{key_string}:\n"
convert(v, spaces.size + 2, proc)
end
end
#proc.call spaces + "}\n"
else
proc.call spaces + input.to_s + "\n"
end
end
end
UserApp.new.write_translations