#!/usr/bin/ruby
# program name lion
# Wordpress Theme Internationalization Script
# Version 0.01 2009-02-11
# Version 0.02 2009-02-15
# Version 0.03 2009-02-17
# Made by Zephyr(mitsu@nishinari.or.jp)
#
require 'tempfile'
if ARGV.size < 1
print "Usage: lion theme_name(required)\n"
exit
else
$theme_name = ARGV.shift
end
#$theme_name = "my_theme"
$domain_name = $theme_name + "_L10N"
$php_script_01 = "title=\"\""
$php_script_02 = "/wp-admin/profile.php\">\" title=\"\">"
$php_script_03 ="\nRSS 2.0 feed.\", '" + $domain_name + "'), get_post_comments_feed_link());\nif (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {\n printf(__('You can leave a response, or trackback from your own site.', '" + $domain_name + "'), trackback_url(false));}\nelseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {\n printf(__(\"Responses are currently closed, but you can trackback from your own site.\", '" + $domain_name + "'), trackback_url(false));}\nelseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {\n _e('You can skip to the end and leave a response. Pinging is currently not allowed.', '" + $domain_name + "');}\nelseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {\n _e('Both comments and pings are currently closed.', '" + $domain_name + "');}\nedit_post_link(__('Edit this entry', '" + $domain_name + "'),'','.'); ?>"
$php_script_04 = "
"
$php_script_05 = "logged in to post a comment.', '" + $domain_name + "'),get_option('siteurl') . '/wp-login.php?redirect_to=' . urlencode(get_permalink())); ?>)"
$php_script_06 = ""
$php_script_07 = "%2$s blog archives for the day %3$s.', '" + $domain_name + "'), get_bloginfo('url'), get_bloginfo('name') "
$php_script_08 =",get_the_time(__('l, F jS, Y', '" + $domain_name + "'))); ?>"
$php_script_09 =",get_the_time(__('F, Y', '" + $domain_name + "'))); ?>"
$php_script_10 = ",get_the_time(__('Y','" + $domain_name + "'))); ?>"
$php_script_11 = "%2$s blog archives for ‘%3$s’. If you are unable to find anything in these search results, you can try one of these links.', '" + $domain_name + "'), get_bloginfo('url'), get_bloginfo('name'), wp_specialchars(get_search_query(), true)); ?>"
$php_script_12 = $php_script_07 + "); ?>"
if not File.exists?("functions.php")
print "Your thema files are incomplete.\nPlease find completed theme files or make and publish them in internet.\nThank you !\n"
exit
end
File.open("functions.php","r") {|f|
f.each {|line|
if line =~ /load_theme_textdomain/
print "Your thema files are already localized.\nPlease find your localized file or make and publish it in internet.\nThank you !\n"
exit
end
}
}
temp = Tempfile.new("functions.tmp")
File.open("functions.php","r") {|f|
temp.puts ""
f.each {|line|
temp.puts(line)
}
}
temp.close
temp.open
File.open("functions.php", "w") {|f| temp.each {|line| f.puts(line) }}
temp.close(true)
Dir.glob("*.php").each {|php|
temp = Tempfile.new(File.basename(php,".*") + ".tmp")
File.open(php,"r") {|f|
f.each {|line|
if line =~ /the_tags\(\'Tags:/
line.gsub!(/the_tags\(\'(Tags:)(.*)'\)/,"the_tags(__('\\1','" + $domain_name + "') , ' \\2')")
line.gsub!(/Posted in/,"")
line.gsub!(/\'Edit\'/,"__('Edit', '" + $domain_name + "')")
line.gsub!(/\'No Comments.*% Comments \&\#187;\'/,"__('No Comments »','" + $domain_name + "'), __('1 Comment »','" + $domain_name + "'), __('% Comments »','" +$domain_name + "')")
elsif line =~ /title=\"Permanent/
line.gsub!(/title=\".*\"/,$php_script_01)
elsif line =~ /the_time/
line.gsub!(/the_time\((\'.*\')\)/,"the_time(__(\\1,'" + $domain_name + "'))")
elsif line =~ /the_content\(.*\)/
line.gsub!(/the_content\('(.*)'\)/,"the_content(__('\\1', '" + $domain_name + "'))")
elsif line =~ /.*<\/p>'); ?>/
line.gsub!(/)(.*)(<\/p>)'); ?>/,"\\1\\3")
elsif line =~ /the_tags\( \'
Tags:/
line.gsub!(/the_tags\( \'(
Tags:)(.*)\'\)/,"the_tags(__('\\1','" + $domain_name + "') , ' \\2')")
elsif line =~ /Older Entries/
line.gsub!(/next_posts_link\(\'« Older Entries\'\)/,"next_posts_link(__('« Older Entries','" +$domain_name + "'))")
elsif line =~ /Newer Entries/
line.gsub!(/previous_posts_link\(\'Newer Entries »\'\)/,"previous_posts_link(__('Newer Entries »','" +$domain_name + "'))")
elsif line =~ /Not Found/
line.gsub!(/Not Found/,"")
elsif line =~ /Sorry/
line.gsub!(/Sorry(.*)\'(.*)\./,"")
elsif line =~ /This post is password/
line.gsub!(/This post is password(.*)\./,"")
elsif line =~ /comments_number/
line.gsub!(/\'No Responses\'/,"__('No Responses', '" + $domain_name + "')")
line.gsub!(/\'One Response\'/,"__('One Response', '" + $domain_name + "')")
line.gsub!(/\'% Responses\'/,"__('% Responses', '" + $domain_name + "')");
line.gsub!(/to.*8221;/,"")
elsif line =~ /comment_form_title/
line.gsub!(/'Leave a Reply', 'Leave a Reply to %s' /,"__('Leave a Reply','" + $domain_name + "'), __('Leave a Reply for %s' ,'" + $domain_name + "')")
elsif line =~ /Leave a Reply/
line.gsub!(/Leave a Reply/,"")
elsif line =~ /Comments are closed\./
line.gsub!(/Comments are closed\./,"")
elsif line =~ /Says:/
line.gsub!(/Says:/,"")
elsif line =~/logged in<\/a> to post a comment./
line.gsub!(/You must be .* post a comment./,$php_script_05)
elsif line =~/Logged in as.*Log out »<\/a>/
line.gsub!(/Logged in as.*Log out »<\/a>/,$php_script_02)
elsif line =~/
'); ?>")
end
temp.puts(line)
}
}
temp.open
File.open("page.php", "w") {|f| temp.each {|line| f.puts(line) }}
temp.close(true)
if File.exists?("search.php")
temp = Tempfile.new("search.tmp")
temp.open
File.open("search.php","r") {|f|
f.each {|line|
if line =~ /Search Results/
line.gsub!(/Search Results/,"")
elsif line =~ /No posts found\. Try a different search\?/
line.gsub!(/No posts found\. Try a different search\?/,"")
end
temp.puts(line)
}
}
temp.open
File.open("search.php", "w") {|f| temp.each {|line| f.puts(line) }}
temp.close(true)
end
temp = Tempfile.new("footer.tmp")
temp.open
File.open("footer.php","r") {|f|
f.each {|line|
if line =~ /Powered by .* /
line.gsub!(/(Powered by .* )/,"\\1() ")
elsif line =~ /Entries \(RSS\)/
line.gsub!(/Entries \(RSS\)/,"")
line.gsub!(/Comments \(RSS\)/,"")
end
temp.puts(line)
}
}
temp.open
File.open("footer.php", "w") {|f| temp.each {|line| f.puts(line) }}
temp.close(true)
if File.exists?("sidebar.php")
temp = Tempfile.new("sidebar.tmp")
temp.open
File.open("sidebar.php","r") {|f|
f.each {|line|
if line =~ /Categories/
line.gsub!(/(Categories)/,"")
elsif line =~ /Author/
line.gsub!(/(Author)/,"")
elsif line =~ /Archive/
line.gsub!(/(Archive)/,"")
elsif line =~ /Meta/
line.gsub!(/(Meta)/,"")
elsif line =~ /XFN/
line.gsub!(/(XFN)/,"")
elsif line =~ /Search/
line.gsub!(/(Search)/,"")
elsif line =~ /Bookmarks/
line.gsub!(/(Bookmarks)/,"")
elsif line =~ /You are currently browsing the archives for the .*category\./
line.gsub!(/You are currently browsing the archives for the .*category\./,$php_script_06)
elsif line =~ /You are currently browsing the .* blog archives\.<\/p>/
line.gsub!(/You are currently browsing the .* blog archives\.<\/p>/,$php_script_12 + "")
elsif line =~ /You are currently browsing the .* blog archives/
line.gsub!(/You are currently browsing the .* blog archives/,$php_script_07)
elsif line =~ /for .*l, F jS, Y.*/
line.gsub!(/for .*l, F jS, Y.* ?>\./,$php_script_08)
elsif line =~ /for .*F, Y.* ?>\./
line.gsub!(/for .*F, Y.* ?>\./,$php_script_09)
elsif line =~ /for .*\'Y\'.* ?>\./
line.gsub!(/for .*\'Y\'.* ?>\./,$php_script_10)
elsif line =~ /You have searched/
line.gsub!(/You have searched the .* blog archives/,$php_script_11)
elsif line =~ /If you are unable to find anything/
line = ""
end
temp.puts(line)
}
}
temp.open
File.open("sidebar.php", "w") {|f| temp.each {|line| f.puts(line) }}
temp.close(true)
end
if File.exists?("sidebar1.php")
temp = Tempfile.new("sidebar1.tmp")
temp.open
File.open("sidebar1.php","r") {|f|
f.each {|line|
if line =~ /Categories/
line.gsub!(/(Categories)/,"")
elsif line =~ /Author/
line.gsub!(/(Author)/,"")
elsif line =~ /Archive/
line.gsub!(/(Archive)/,"")
elsif line =~ /Meta/
line.gsub!(/(Meta)/,"")
elsif line =~ /XFN/
line.gsub!(/(XFN)/,"")
elsif line =~ /Search/
line.gsub!(/(Search)/,"")
elsif line =~ /Bookmarks/
line.gsub!(/(Bookmarks)/,"")
elsif line =~ /You are currently browsing the archives for the .*category\./
line.gsub!(/You are currently browsing the archives for the .*category\./,$php_script_06)
elsif line =~ /You are currently browsing the .* blog archives\.<\/p>/
line.gsub!(/You are currently browsing the .* blog archives\.<\/p>/,$php_script_12 + "")
elsif line =~ /You are currently browsing the .* blog archives/
line.gsub!(/You are currently browsing the .* blog archives/,$php_script_07)
elsif line =~ /for .*l, F jS, Y.*/
line.gsub!(/for .*l, F jS, Y.* ?>\./,$php_script_08)
elsif line =~ /for .*F, Y.* ?>\./
line.gsub!(/for .*F, Y.* ?>\./,$php_script_09)
elsif line =~ /for .*\'Y\'.* ?>\./
line.gsub!(/for .*\'Y\'.* ?>\./,$php_script_10)
elsif line =~ /You have searched/
line.gsub!(/You have searched the .* blog archives/,$php_script_11)
elsif line =~ /If you are unable to find anything/
line = ""
end
temp.puts(line)
}
}
temp.open
File.open("sidebar1.php", "w") {|f| temp.each {|line| f.puts(line) }}
temp.close(true)
end
if File.exists?("sidebar2.php")
temp = Tempfile.new("sidebar2.tmp")
temp.open
File.open("sidebar2.php","r") {|f|
f.each {|line|
if line =~ /Categories/
line.gsub!(/(Categories)/,"")
elsif line =~ /Author/
line.gsub!(/(Author)/,"")
elsif line =~ /Archive/
line.gsub!(/(Archive)/,"")
elsif line =~ /Meta/
line.gsub!(/(Meta)/,"")
elsif line =~ /XFN/
line.gsub!(/(XFN)/,"")
elsif line =~ /Search/
line.gsub!(/(Search)/,"")
elsif line =~ /Bookmarks/
line.gsub!(/(Bookmarks)/,"")
elsif line =~ /You are currently browsing the archives for the .*category\./
line.gsub!(/You are currently browsing the archives for the .*category\./,$php_script_06)
elsif line =~ /You are currently browsing the .* blog archives\.<\/p>/
line.gsub!(/You are currently browsing the .* blog archives\.<\/p>/,$php_script_12 + "")
elsif line =~ /You are currently browsing the .* blog archives/
line.gsub!(/You are currently browsing the .* blog archives/,$php_script_07)
elsif line =~ /for .*l, F jS, Y.*/
line.gsub!(/for .*l, F jS, Y.* ?>\./,$php_script_08)
elsif line =~ /for .*F, Y.* ?>\./
line.gsub!(/for .*F, Y.* ?>\./,$php_script_09)
elsif line =~ /for .*\'Y\'.* ?>\./
line.gsub!(/for .*\'Y\'.* ?>\./,$php_script_10)
elsif line =~ /You have searched/
line.gsub!(/You have searched the .* blog archives/,$php_script_11)
elsif line =~ /If you are unable to find anything/
line = ""
end
temp.puts(line)
}
}
temp.open
File.open("sidebar2.php", "w") {|f| temp.each {|line| f.puts(line) }}
temp.close(true)
end