as3gettext 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +4 -0
- data/README +29 -0
- data/Rakefile +135 -0
- data/as3lib/_.as +7 -0
- data/as3lib/com/rails2u/gettext/GetText.as +46 -0
- data/as3lib/com/rails2u/gettext/GetTextText.as +12 -0
- data/bin/as3gettext +10 -0
- data/lib/as3gettext.rb +4 -0
- data/lib/as3gettext/as3_parser.rb +37 -0
- data/lib/as3gettext/command.rb +56 -0
- data/lib/as3gettext/generate_xml.rb +48 -0
- data/test/as3gettext_test.rb +5 -0
- data/test/test_helper.rb +3 -0
- metadata +88 -0
data/ChangeLog
ADDED
data/README
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
= as3gettext
|
3
|
+
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
=== Archive Installation
|
11
|
+
|
12
|
+
rake install
|
13
|
+
|
14
|
+
=== Gem Installation
|
15
|
+
|
16
|
+
gem install as3gettext
|
17
|
+
|
18
|
+
|
19
|
+
== Features/Problems
|
20
|
+
|
21
|
+
|
22
|
+
== Synopsis
|
23
|
+
|
24
|
+
|
25
|
+
== Copyright
|
26
|
+
|
27
|
+
Author:: Yuichi Tateno <hotchpotch@no.spam@gmail.com>
|
28
|
+
Copyright:: Copyright (c) 2008 Yuichi Tateno
|
29
|
+
License:: MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'rake/contrib/sshpublisher'
|
10
|
+
require 'fileutils'
|
11
|
+
include FileUtils
|
12
|
+
|
13
|
+
NAME = "as3gettext"
|
14
|
+
AUTHOR = "Yuichi Tateno"
|
15
|
+
EMAIL = "hotchpotch@remove@gmail.com"
|
16
|
+
DESCRIPTION = "gettext for actionscript"
|
17
|
+
RUBYFORGE_PROJECT = "hotchpotch"
|
18
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org/rascut/"
|
19
|
+
BIN_FILES = %w(as3gettext)
|
20
|
+
VERS = "0.0.1"
|
21
|
+
|
22
|
+
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
24
|
+
RDOC_OPTS = [
|
25
|
+
'--title', "#{NAME} documentation",
|
26
|
+
"--charset", "utf-8",
|
27
|
+
"--opname", "index.html",
|
28
|
+
"--line-numbers",
|
29
|
+
"--main", "README",
|
30
|
+
"--inline-source",
|
31
|
+
]
|
32
|
+
|
33
|
+
task :default => [:test]
|
34
|
+
task :package => [:clean]
|
35
|
+
|
36
|
+
Rake::TestTask.new("test") do |t|
|
37
|
+
t.libs << "test"
|
38
|
+
t.pattern = "test/**/*_test.rb"
|
39
|
+
t.verbose = true
|
40
|
+
end
|
41
|
+
|
42
|
+
spec = Gem::Specification.new do |s|
|
43
|
+
s.name = NAME
|
44
|
+
s.version = VERS
|
45
|
+
s.platform = Gem::Platform::RUBY
|
46
|
+
s.has_rdoc = true
|
47
|
+
s.extra_rdoc_files = ["README", "ChangeLog"]
|
48
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
49
|
+
s.summary = DESCRIPTION
|
50
|
+
s.description = DESCRIPTION
|
51
|
+
s.author = AUTHOR
|
52
|
+
s.email = EMAIL
|
53
|
+
s.homepage = HOMEPATH
|
54
|
+
s.executables = BIN_FILES
|
55
|
+
s.rubyforge_project = RUBYFORGE_PROJECT
|
56
|
+
s.bindir = "bin"
|
57
|
+
s.require_path = "lib"
|
58
|
+
s.autorequire = ""
|
59
|
+
s.test_files = Dir["test/test_*.rb"]
|
60
|
+
|
61
|
+
s.add_dependency('gettext')
|
62
|
+
s.add_dependency('builder')
|
63
|
+
#s.add_dependency('activesupport', '>=1.3.1')
|
64
|
+
#s.required_ruby_version = '>= 1.8.2'
|
65
|
+
|
66
|
+
s.files = %w(README ChangeLog Rakefile) +
|
67
|
+
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
68
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
69
|
+
Dir.glob("as3lib/**/*.as") +
|
70
|
+
Dir.glob("examples/**/*.rb") +
|
71
|
+
Dir.glob("tools/*.rb")
|
72
|
+
|
73
|
+
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
74
|
+
end
|
75
|
+
|
76
|
+
Rake::GemPackageTask.new(spec) do |p|
|
77
|
+
p.need_tar = true
|
78
|
+
p.gem_spec = spec
|
79
|
+
end
|
80
|
+
|
81
|
+
task :install do
|
82
|
+
name = "#{NAME}-#{VERS}.gem"
|
83
|
+
sh %{rake package}
|
84
|
+
sh %{sudo gem install pkg/#{name}}
|
85
|
+
end
|
86
|
+
|
87
|
+
task :uninstall => [:clean] do
|
88
|
+
sh %{sudo gem uninstall #{NAME}}
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
Rake::RDocTask.new do |rdoc|
|
93
|
+
rdoc.rdoc_dir = 'html'
|
94
|
+
rdoc.options += RDOC_OPTS
|
95
|
+
rdoc.template = "resh"
|
96
|
+
#rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
97
|
+
if ENV['DOC_FILES']
|
98
|
+
rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
99
|
+
else
|
100
|
+
rdoc.rdoc_files.include('README', 'ChangeLog')
|
101
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
102
|
+
rdoc.rdoc_files.include('ext/**/*.c')
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
desc "Publish to RubyForge"
|
107
|
+
task :rubyforge => [:rdoc, :package] do
|
108
|
+
require 'rubyforge'
|
109
|
+
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'secondlife').upload
|
110
|
+
end
|
111
|
+
|
112
|
+
desc 'Package and upload the release to rubyforge.'
|
113
|
+
task :release => [:clean, :package] do |t|
|
114
|
+
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
115
|
+
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
|
116
|
+
pkg = "pkg/#{NAME}-#{VERS}"
|
117
|
+
|
118
|
+
require 'rubyforge'
|
119
|
+
rf = RubyForge.new
|
120
|
+
puts "Logging in"
|
121
|
+
rf.login
|
122
|
+
|
123
|
+
c = rf.userconfig
|
124
|
+
# c["release_notes"] = description if description
|
125
|
+
# c["release_changes"] = changes if changes
|
126
|
+
c["preformatted"] = true
|
127
|
+
|
128
|
+
files = [
|
129
|
+
"#{pkg}.tgz",
|
130
|
+
"#{pkg}.gem"
|
131
|
+
].compact
|
132
|
+
|
133
|
+
puts "Releasing #{NAME} v. #{VERS}"
|
134
|
+
rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
|
135
|
+
end
|
data/as3lib/_.as
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
package com.rails2u.gettext {
|
2
|
+
import flash.system.Capabilities;
|
3
|
+
|
4
|
+
public class GetText {
|
5
|
+
public static var locale:String = Capabilities.language;
|
6
|
+
public static var defaultLocale:String = 'en';
|
7
|
+
|
8
|
+
public static function _(str:String, args:Array = null):String {
|
9
|
+
var res:String;
|
10
|
+
if (cacheLangStrings[locale] && cacheLangStrings[locale][str]) {
|
11
|
+
res = cacheLangStrings[locale][str];
|
12
|
+
} else if (cacheLangStrings[defaultLocale] && cacheLangStrings[defaultLocale][str]) {
|
13
|
+
res = cacheLangStrings[defaultLocale][str];
|
14
|
+
} else {
|
15
|
+
res = str;
|
16
|
+
}
|
17
|
+
if (args) res = sprintf(res, args);
|
18
|
+
return res;
|
19
|
+
}
|
20
|
+
|
21
|
+
public static function sprintf(str:String, args:Array = null):String {
|
22
|
+
args = args.slice();
|
23
|
+
return str.replace(/%s/g, function():String {
|
24
|
+
return args.shift();
|
25
|
+
});
|
26
|
+
}
|
27
|
+
|
28
|
+
private static var cacheLangStrings:Object = {};
|
29
|
+
public static function initLangFile(xml:XML):void {
|
30
|
+
var origIgnoreWhiteSpace:Boolean = XML.ignoreWhitespace;
|
31
|
+
XML.ignoreWhitespace = false;
|
32
|
+
try {
|
33
|
+
for each (var lang:XML in xml.lang) {
|
34
|
+
var langname:String = lang.@lang.toString();
|
35
|
+
var res:Object = {};
|
36
|
+
for each (var message:XML in lang.message) {
|
37
|
+
res[message.msgid.toString()] = message.msgstr.toString();
|
38
|
+
}
|
39
|
+
cacheLangStrings[langname] = res;
|
40
|
+
}
|
41
|
+
} finally {
|
42
|
+
XML.ignoreWhitespace = origIgnoreWhiteSpace;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
data/bin/as3gettext
ADDED
data/lib/as3gettext.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'gettext'
|
2
|
+
require 'gettext/rgettext'
|
3
|
+
|
4
|
+
module As3gettext
|
5
|
+
module As3Parser
|
6
|
+
module_function
|
7
|
+
def parse(file, targets = []) # :nodoc:
|
8
|
+
lines = IO.readlines(file)
|
9
|
+
parse_lines(file, lines, targets)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_lines(file_name, lines, targets) # :nodoc:
|
13
|
+
begin
|
14
|
+
lines.each_with_index do |line, i|
|
15
|
+
if m = (line.match(/_\('([^']+)'\)/) || line.match(/_\("([^"]+)"\)/) )
|
16
|
+
name = m[1].gsub(/\n/, '\n')
|
17
|
+
if t = targets.detect{|a| a[0] == name}
|
18
|
+
t[1] << ', ' + file_name + ":" + (i+1).to_s
|
19
|
+
else
|
20
|
+
targets << [name, file_name + ":" + (i+1).to_s]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
rescue
|
25
|
+
$stderr.print "\n\nError: #{$!.inspect} "
|
26
|
+
$stderr.print " in #{file_name}:#{tk.line_no}\n\t #{lines[tk.line_no - 1]}" if tk
|
27
|
+
$stderr.print "\n"
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
targets
|
31
|
+
end
|
32
|
+
|
33
|
+
def target?(file)
|
34
|
+
['.as', '.mxml'].include? File.extname(file)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'gettext'
|
3
|
+
require 'gettext/rgettext'
|
4
|
+
require 'as3gettext/as3_parser'
|
5
|
+
require 'as3gettext/generate_xml'
|
6
|
+
|
7
|
+
module As3gettext
|
8
|
+
class Command
|
9
|
+
include GetText
|
10
|
+
def initialize
|
11
|
+
@config = {
|
12
|
+
:mode => :gettext
|
13
|
+
}
|
14
|
+
end
|
15
|
+
attr_accessor :config
|
16
|
+
|
17
|
+
def run(argv)
|
18
|
+
parse argv
|
19
|
+
send @config[:mode]
|
20
|
+
end
|
21
|
+
|
22
|
+
def gettext
|
23
|
+
RGetText.add_parser As3gettext::As3Parser
|
24
|
+
GetText.rgettext config[:targets], config[:output] || STDOUT
|
25
|
+
end
|
26
|
+
|
27
|
+
def xml
|
28
|
+
xml_string = GenerateXml.new.generate config[:targets]
|
29
|
+
if config[:output]
|
30
|
+
File.open(config[:output], 'w') do |f|
|
31
|
+
f.puts xml_string
|
32
|
+
end
|
33
|
+
else
|
34
|
+
puts xml_string
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse(argv)
|
39
|
+
op = OptionParser.new
|
40
|
+
op.banner = <<-EOF.gsub(/^\s+/, '')
|
41
|
+
Usage:
|
42
|
+
$ as3gettext src/HelloWrold.as src/**/*.mxml -o template.pot
|
43
|
+
$ as3gettext i18n/**.po -x -o langs.xml
|
44
|
+
EOF
|
45
|
+
op.on('-h', '--help', 'show this message') { puts op; Kernel::exit 1 }
|
46
|
+
op.on('-x', 'export XML') { config[:mode] = :xml }
|
47
|
+
op.on('-o=VAL', 'output file') {|v| config[:output] = v }
|
48
|
+
op.parse! argv
|
49
|
+
if argv.length == 0
|
50
|
+
puts op
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
config[:targets] = argv
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'gettext'
|
2
|
+
require 'gettext/poparser'
|
3
|
+
require 'gettext/mo'
|
4
|
+
require 'builder'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
$KCODE = 'u'
|
8
|
+
$DEBUG = false
|
9
|
+
|
10
|
+
module As3gettext
|
11
|
+
class GenerateXml
|
12
|
+
include GetText
|
13
|
+
include Builder
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@parser = PoParser.new
|
17
|
+
@xml_declaration = false
|
18
|
+
end
|
19
|
+
attr_accessor :xml_declaration
|
20
|
+
|
21
|
+
def generate(files)
|
22
|
+
files.map! {|f| Pathname.new(f) }
|
23
|
+
res = ''
|
24
|
+
xml = XmlMarkup.new(:indent => 2, :target => res)
|
25
|
+
xml.instruct! :xml, :version=>"1.0", :encoding=> "UTF-8" if xml_declaration
|
26
|
+
xml.langs do
|
27
|
+
files.each do |file|
|
28
|
+
langname = file.basename('.po').to_s
|
29
|
+
unless langname.empty?
|
30
|
+
data = MOFile.new
|
31
|
+
@parser.parse(file.read, data)
|
32
|
+
xml.lang(:lang => langname) {
|
33
|
+
data.each do |msgid, msgstr|
|
34
|
+
next if msgid.length == 0
|
35
|
+
xml.message {
|
36
|
+
xml.msgid(msgid)
|
37
|
+
xml.msgstr(msgstr)
|
38
|
+
}
|
39
|
+
end
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
res.gsub(/&#([\d+]+);/){[$1.to_i].pack("U")}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.1
|
3
|
+
specification_version: 1
|
4
|
+
name: as3gettext
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2008-01-15 00:00:00 +09:00
|
8
|
+
summary: gettext for actionscript
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: hotchpotch@remove@gmail.com
|
12
|
+
homepage: http://hotchpotch.rubyforge.org/rascut/
|
13
|
+
rubyforge_project: hotchpotch
|
14
|
+
description: gettext for actionscript
|
15
|
+
autorequire: ""
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Yuichi Tateno
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- ChangeLog
|
34
|
+
- Rakefile
|
35
|
+
- bin/as3gettext
|
36
|
+
- test/test_helper.rb
|
37
|
+
- test/as3gettext_test.rb
|
38
|
+
- lib/as3gettext.rb
|
39
|
+
- lib/as3gettext
|
40
|
+
- lib/as3gettext/as3_parser.rb
|
41
|
+
- lib/as3gettext/generate_xml.rb
|
42
|
+
- lib/as3gettext/command.rb
|
43
|
+
- as3lib/com/rails2u/gettext/GetTextText.as
|
44
|
+
- as3lib/com/rails2u/gettext/GetText.as
|
45
|
+
- as3lib/_.as
|
46
|
+
test_files:
|
47
|
+
- test/test_helper.rb
|
48
|
+
rdoc_options:
|
49
|
+
- --title
|
50
|
+
- as3gettext documentation
|
51
|
+
- --charset
|
52
|
+
- utf-8
|
53
|
+
- --opname
|
54
|
+
- index.html
|
55
|
+
- --line-numbers
|
56
|
+
- --main
|
57
|
+
- README
|
58
|
+
- --inline-source
|
59
|
+
- --exclude
|
60
|
+
- ^(examples|extras)/
|
61
|
+
extra_rdoc_files:
|
62
|
+
- README
|
63
|
+
- ChangeLog
|
64
|
+
executables:
|
65
|
+
- as3gettext
|
66
|
+
extensions: []
|
67
|
+
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
dependencies:
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: gettext
|
73
|
+
version_requirement:
|
74
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">"
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.0.0
|
79
|
+
version:
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: builder
|
82
|
+
version_requirement:
|
83
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.0.0
|
88
|
+
version:
|