as3gettext-oneup 0.0.2

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 ADDED
@@ -0,0 +1,8 @@
1
+ == 0.0.2 / 2010-11-12
2
+
3
+ * fixed for gettext 2.1.0
4
+
5
+ == 0.0.1 / 2008-01-15
6
+
7
+ * initial release
8
+
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+
2
+ = as3gettext-oneup
3
+
4
+ This is forked from http://coderepos.org/share/browser/lang/ruby/as3gettext/trunk/
5
+
6
+ == Description
7
+
8
+
9
+ == Installation
10
+
11
+ === Archive Installation
12
+
13
+ rake install
14
+
15
+ === Gem Installation
16
+
17
+ gem install as3gettext-oneup
18
+
19
+
20
+ == Features/Problems
21
+
22
+
23
+ == Synopsis
24
+
25
+
26
+ == Copyright
27
+
28
+ === Original
29
+ Author:: Yuichi Tateno <hotchpotch@no.spam@gmail.com>
30
+ Copyright:: Copyright (c) 2008 Yuichi Tateno
31
+ License:: MIT License
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "as3gettext-oneup"
8
+ gem.summary = %Q{gettext for as3}
9
+ gem.description = %Q{gettext for as3}
10
+ gem.email = "toshi.hirooka@gmail.com"
11
+ gem.homepage = "http://github.com/tosik/as3gettext-oneup"
12
+ gem.authors = ["Yuichi Tateno", "Toshiyuki Hirooka"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "as3gettext-oneup #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/as3lib/_.as ADDED
@@ -0,0 +1,7 @@
1
+ package {
2
+ import com.rails2u.gettext.GetText;
3
+
4
+ public function _(str:String, ... args):* {
5
+ return GetText._(str, args);
6
+ }
7
+ }
@@ -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
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'as3gettext/command'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'as3gettext/command'
8
+ end
9
+
10
+ As3gettext::Command.new.run ARGV
@@ -0,0 +1,37 @@
1
+ require 'gettext'
2
+ require 'gettext/tools/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/tools/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,47 @@
1
+ require 'gettext'
2
+ require 'gettext/tools/poparser'
3
+ require 'builder'
4
+ require 'pathname'
5
+
6
+ $KCODE = 'u'
7
+ $DEBUG = false
8
+
9
+ module As3gettext
10
+ class GenerateXml
11
+ include GetText
12
+ include Builder
13
+
14
+ def initialize
15
+ @parser = PoParser.new
16
+ @xml_declaration = false
17
+ end
18
+ attr_accessor :xml_declaration
19
+
20
+ def generate(files)
21
+ files.map! {|f| Pathname.new(f) }
22
+ res = ''
23
+ xml = XmlMarkup.new(:indent => 2, :target => res)
24
+ xml.instruct! :xml, :version=>"1.0", :encoding=> "UTF-8" if xml_declaration
25
+ xml.langs do
26
+ files.each do |file|
27
+ langname = file.basename('.po').to_s
28
+ unless langname.empty?
29
+ data = MOFile.new
30
+ @parser.parse(file.read, data)
31
+ xml.lang(:lang => langname) {
32
+ data.each do |msgid, msgstr|
33
+ next if msgid.length == 0
34
+ xml.message {
35
+ xml.msgid(msgid)
36
+ xml.msgstr(msgstr)
37
+ }
38
+ end
39
+ }
40
+ end
41
+ end
42
+ end
43
+
44
+ res.gsub(/&#([\d+]+);/){[$1.to_i].pack("U")}
45
+ end
46
+ end
47
+ end
data/lib/as3gettext.rb ADDED
@@ -0,0 +1,4 @@
1
+
2
+ module As3gettext
3
+ VERSION = '0.0.2'
4
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'as3gettext'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,4 @@
1
+ require 'helper'
2
+
3
+ class TestAs3gettext < Test::Unit::TestCase
4
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: as3gettext-oneup
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Yuichi Tateno
13
+ - Toshiyuki Hirooka
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-16 00:00:00 +09:00
19
+ default_executable: as3gettext
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: gettext for as3
35
+ email: toshi.hirooka@gmail.com
36
+ executables:
37
+ - as3gettext
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - ChangeLog
42
+ - README.rdoc
43
+ files:
44
+ - ChangeLog
45
+ - README.rdoc
46
+ - Rakefile
47
+ - VERSION
48
+ - as3lib/_.as
49
+ - as3lib/com/rails2u/gettext/GetText.as
50
+ - bin/as3gettext
51
+ - lib/as3gettext.rb
52
+ - lib/as3gettext/as3_parser.rb
53
+ - lib/as3gettext/command.rb
54
+ - lib/as3gettext/generate_xml.rb
55
+ - test/helper.rb
56
+ - test/test_as3gettext.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/tosik/as3gettext-oneup
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.3.7
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: gettext for as3
89
+ test_files:
90
+ - test/test_as3gettext.rb
91
+ - test/helper.rb