talk_like_a_pirate 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/Gemfile +1 -0
- data/Gemfile.lock +85 -0
- data/lib/talk_like_a_pirate/pirate_booty.yml +109 -0
- data/lib/talk_like_a_pirate/railties.rb +5 -0
- data/lib/talk_like_a_pirate/tasks/pirate.rake +57 -0
- data/lib/talk_like_a_pirate.rb +76 -0
- data/talk_like_a_pirate.gemspec +14 -0
- metadata +52 -0
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem "rails", "~> 3.0"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
GEM
|
2
|
+
specs:
|
3
|
+
actionmailer (3.2.13)
|
4
|
+
actionpack (= 3.2.13)
|
5
|
+
mail (~> 2.5.3)
|
6
|
+
actionpack (3.2.13)
|
7
|
+
activemodel (= 3.2.13)
|
8
|
+
activesupport (= 3.2.13)
|
9
|
+
builder (~> 3.0.0)
|
10
|
+
erubis (~> 2.7.0)
|
11
|
+
journey (~> 1.0.4)
|
12
|
+
rack (~> 1.4.5)
|
13
|
+
rack-cache (~> 1.2)
|
14
|
+
rack-test (~> 0.6.1)
|
15
|
+
sprockets (~> 2.2.1)
|
16
|
+
activemodel (3.2.13)
|
17
|
+
activesupport (= 3.2.13)
|
18
|
+
builder (~> 3.0.0)
|
19
|
+
activerecord (3.2.13)
|
20
|
+
activemodel (= 3.2.13)
|
21
|
+
activesupport (= 3.2.13)
|
22
|
+
arel (~> 3.0.2)
|
23
|
+
tzinfo (~> 0.3.29)
|
24
|
+
activeresource (3.2.13)
|
25
|
+
activemodel (= 3.2.13)
|
26
|
+
activesupport (= 3.2.13)
|
27
|
+
activesupport (3.2.13)
|
28
|
+
i18n (= 0.6.1)
|
29
|
+
multi_json (~> 1.0)
|
30
|
+
arel (3.0.2)
|
31
|
+
builder (3.0.4)
|
32
|
+
erubis (2.7.0)
|
33
|
+
hike (1.2.2)
|
34
|
+
i18n (0.6.1)
|
35
|
+
journey (1.0.4)
|
36
|
+
json (1.7.7)
|
37
|
+
mail (2.5.3)
|
38
|
+
i18n (>= 0.4.0)
|
39
|
+
mime-types (~> 1.16)
|
40
|
+
treetop (~> 1.4.8)
|
41
|
+
mime-types (1.22)
|
42
|
+
multi_json (1.7.2)
|
43
|
+
polyglot (0.3.3)
|
44
|
+
rack (1.4.5)
|
45
|
+
rack-cache (1.2)
|
46
|
+
rack (>= 0.4)
|
47
|
+
rack-ssl (1.3.3)
|
48
|
+
rack
|
49
|
+
rack-test (0.6.2)
|
50
|
+
rack (>= 1.0)
|
51
|
+
rails (3.2.13)
|
52
|
+
actionmailer (= 3.2.13)
|
53
|
+
actionpack (= 3.2.13)
|
54
|
+
activerecord (= 3.2.13)
|
55
|
+
activeresource (= 3.2.13)
|
56
|
+
activesupport (= 3.2.13)
|
57
|
+
bundler (~> 1.0)
|
58
|
+
railties (= 3.2.13)
|
59
|
+
railties (3.2.13)
|
60
|
+
actionpack (= 3.2.13)
|
61
|
+
activesupport (= 3.2.13)
|
62
|
+
rack-ssl (~> 1.3.2)
|
63
|
+
rake (>= 0.8.7)
|
64
|
+
rdoc (~> 3.4)
|
65
|
+
thor (>= 0.14.6, < 2.0)
|
66
|
+
rake (10.0.4)
|
67
|
+
rdoc (3.12.2)
|
68
|
+
json (~> 1.4)
|
69
|
+
sprockets (2.2.2)
|
70
|
+
hike (~> 1.2)
|
71
|
+
multi_json (~> 1.0)
|
72
|
+
rack (~> 1.0)
|
73
|
+
tilt (~> 1.1, != 1.3.0)
|
74
|
+
thor (0.18.1)
|
75
|
+
tilt (1.3.7)
|
76
|
+
treetop (1.4.12)
|
77
|
+
polyglot
|
78
|
+
polyglot (>= 0.3.1)
|
79
|
+
tzinfo (0.3.37)
|
80
|
+
|
81
|
+
PLATFORMS
|
82
|
+
ruby
|
83
|
+
|
84
|
+
DEPENDENCIES
|
85
|
+
rails (~> 3.0)
|
@@ -0,0 +1,109 @@
|
|
1
|
+
locale: "arr"
|
2
|
+
dictionary:
|
3
|
+
account: debtor
|
4
|
+
address: port o' call
|
5
|
+
admin: helm
|
6
|
+
am: be
|
7
|
+
an: a
|
8
|
+
and: "n'"
|
9
|
+
are: be
|
10
|
+
beer: grog
|
11
|
+
before: afore
|
12
|
+
big: vast
|
13
|
+
boss: admiral
|
14
|
+
business: company
|
15
|
+
businesses: companies
|
16
|
+
calling: "callin'"
|
17
|
+
cheat: hornswaggle
|
18
|
+
comments: yer words
|
19
|
+
country: king
|
20
|
+
dashboard: shanty
|
21
|
+
disconnect: keelhaul
|
22
|
+
do: "d'"
|
23
|
+
employee: crew
|
24
|
+
everyone: all hands
|
25
|
+
eye: eye-patch
|
26
|
+
for: fer
|
27
|
+
friend: shipmate
|
28
|
+
girl: lass
|
29
|
+
girls: lassies
|
30
|
+
go: sail
|
31
|
+
good: jolly good
|
32
|
+
group: maties
|
33
|
+
hand: hook
|
34
|
+
hello: ahoy
|
35
|
+
hey: ahoy
|
36
|
+
home: shanty
|
37
|
+
"i'm": i be
|
38
|
+
invalid: sunk
|
39
|
+
is: be
|
40
|
+
"isn't": be not
|
41
|
+
kill: keelhaul
|
42
|
+
leg: peg
|
43
|
+
logout: walk the plank
|
44
|
+
manager: admiral
|
45
|
+
my: me
|
46
|
+
never: nary
|
47
|
+
no: nay
|
48
|
+
of: "o'"
|
49
|
+
over: "o'er"
|
50
|
+
page: parchment
|
51
|
+
person: scallywag
|
52
|
+
posted: tacked to the yardarm
|
53
|
+
quickly: smartly
|
54
|
+
really: verily
|
55
|
+
role: job
|
56
|
+
say: cry
|
57
|
+
shipping: cargo
|
58
|
+
small: puny
|
59
|
+
sorry: yarr
|
60
|
+
state: isle
|
61
|
+
supervisor: "Cap'n"
|
62
|
+
"that's": that be
|
63
|
+
the: tha
|
64
|
+
them: "'em"
|
65
|
+
this: dis
|
66
|
+
to: t'
|
67
|
+
we: our jolly crew
|
68
|
+
woman: wench
|
69
|
+
work: brig
|
70
|
+
yah: aye
|
71
|
+
yeah: aye
|
72
|
+
yes: aye
|
73
|
+
you: ye
|
74
|
+
"you're": you be
|
75
|
+
your: yer
|
76
|
+
|
77
|
+
pirate_flavor:
|
78
|
+
- avast
|
79
|
+
- splice the mainbrace
|
80
|
+
- shiver me timbers
|
81
|
+
- ahoy
|
82
|
+
- arrrrr
|
83
|
+
- arrgh
|
84
|
+
- yo ho ho
|
85
|
+
- yarrr
|
86
|
+
- eh
|
87
|
+
- arrrghhh
|
88
|
+
- arrr
|
89
|
+
- ahoy matey
|
90
|
+
- prepare to be boarded
|
91
|
+
- hoist the mizzen
|
92
|
+
- blow me down
|
93
|
+
- swab the poop deck
|
94
|
+
- ye landlubber
|
95
|
+
- "bring \'er alongside"
|
96
|
+
- "hang \'im from the yardarm"
|
97
|
+
- blow the man down
|
98
|
+
- let go and haul
|
99
|
+
- heave to
|
100
|
+
- take no prisoners
|
101
|
+
- belay that
|
102
|
+
- me bucko
|
103
|
+
- "lock \'im in irons"
|
104
|
+
- "and a bottle \'o rum"
|
105
|
+
- and donae spare the whip
|
106
|
+
- pass the grog
|
107
|
+
- and swab the deck
|
108
|
+
- fire the cannon
|
109
|
+
- "sleep with t\' fishes"
|
@@ -0,0 +1,57 @@
|
|
1
|
+
namespace "pirate" do
|
2
|
+
desc "Use this task to translate config/locales dictionary into pirrrrate"
|
3
|
+
task :translate, :dir_or_file_to_translate do |t, args|
|
4
|
+
require 'cgi'
|
5
|
+
args.with_defaults(:dir_or_file_to_translate => "config/locales")
|
6
|
+
translate_locale(args[:dir_or_file_to_translate])
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def translate(filename)
|
11
|
+
en_yml = YAML::load_file(filename)
|
12
|
+
target_filename = TalkLikeAPirate.pirate_locale + filename.match(/\/en([a-zA-Z-]*).yml/)[1]
|
13
|
+
dirname = filename.split("/")[0..-2].join("/")
|
14
|
+
translation = {target_filename => parse_element(en_yml).values.first}
|
15
|
+
File.open(dirname + "/#{target_filename}.yml", 'w:utf-8') do |f|
|
16
|
+
YAML::dump translation, f
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def translate_locale(path)
|
21
|
+
path = "#{Rails.root}/#{path}" unless path.include? Rails.root.to_s
|
22
|
+
return translate(path) if File.exists?(path) && path.match("/\/en([a-zA-Z-]*).yml")
|
23
|
+
|
24
|
+
relevent_file_paths(path).each do |file_path|
|
25
|
+
if File.directory? file_path
|
26
|
+
translate(file_path + "/en.yml") if File.exists?(file_path + "/en.yml")
|
27
|
+
translate_locale file_path
|
28
|
+
elsif file_path.match("\/en([a-zA-Z-]*).yml")
|
29
|
+
puts file_path
|
30
|
+
translate file_path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse_element(element)
|
36
|
+
case element
|
37
|
+
when Hash
|
38
|
+
new_hash = {}
|
39
|
+
element.each {|k,v| new_hash[k] = parse_element(v)}
|
40
|
+
new_hash
|
41
|
+
when Array
|
42
|
+
element.map {|el| parse_element(element)}
|
43
|
+
when String
|
44
|
+
TalkLikeAPirate.translate element
|
45
|
+
else
|
46
|
+
element
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def relevent_file_paths(path)
|
51
|
+
Dir.new(path).entries.reject do |filename|
|
52
|
+
[".", ".."].include? filename
|
53
|
+
end.map do |filename|
|
54
|
+
"#{path}/#{filename}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
class TalkLikeAPirate
|
2
|
+
|
3
|
+
def self.translate(me_string)
|
4
|
+
me_string.is_a?(String) ? build_string(me_string) : me_string
|
5
|
+
end
|
6
|
+
|
7
|
+
private #####################################################################
|
8
|
+
|
9
|
+
def self.build_string(me_string)
|
10
|
+
sentence = translate_string(me_string)
|
11
|
+
if sentence.split(" ").length > 5 && rand(5) == 0
|
12
|
+
sentence = prepare_original_sentence(sentence) + " " + build_piratey_sentence
|
13
|
+
end
|
14
|
+
sentence
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.translate_string(me_string)
|
18
|
+
me_string.split(/ /).map do |word|
|
19
|
+
capitalized = (word.slice(0,1) == word.slice(0,1).upcase)
|
20
|
+
pluralized = word.pluralize == word
|
21
|
+
if dictionary.has_key?(word.downcase.singularize)
|
22
|
+
word = dictionary[word.downcase.singularize]
|
23
|
+
word = pluralized ? word.pluralize : word
|
24
|
+
word = capitalized ? capitalize_first(word) : word
|
25
|
+
end
|
26
|
+
word
|
27
|
+
end.join(" ")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.prepare_original_sentence(sentence)
|
31
|
+
sentence.gsub!(/\.\z/, "")
|
32
|
+
sentence = sentence + "." if sentence.match(/\w\z/)
|
33
|
+
capitalize_first(sentence)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.build_piratey_sentence
|
37
|
+
capitalize_first(sprinklings_of_flavor.sample) + ["!!","!","."].sample
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.pirate_locale
|
41
|
+
@@locale ||= local_config.has_key?("locale") ? local_config["locale"] : config["locale"]
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.dictionary
|
45
|
+
@@dictionary_map ||= config["dictionary"].merge(local_dictionary)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.sprinklings_of_flavor
|
49
|
+
@@fill ||= (config["pirate_flavor"] << local_flavor).compact
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.config
|
53
|
+
@@config ||= YAML.load_file(File.dirname(__FILE__) + "/talk_like_a_pirate/pirate_booty.yml")
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.local_dictionary
|
57
|
+
local_config.has_key?("dictionary") ? local_config["dictionary"] : {}
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.local_flavor
|
61
|
+
local_config.has_key?("pirate_flavor") ? local_config["pirate_flavor"] : nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.local_config
|
65
|
+
@@local_configs ||= YAML.load_file("#{Rails.root.to_s}/config/pirate_booty.yml") rescue {}
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.capitalize_first(string)
|
69
|
+
return string unless string.is_a? String
|
70
|
+
return string.upcase if string.length < 2
|
71
|
+
string.slice(0,1).capitalize + string.slice(1..-1)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
require 'talk_like_a_pirate/railties'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = 'talk_like_a_pirate'
|
4
|
+
s.version = '0.0.1'
|
5
|
+
s.authors = ['Steve Hodges']
|
6
|
+
s.email = ['sjhodges@gmail.com']
|
7
|
+
s.homepage = 'https://github.com/stevehodges/'
|
8
|
+
s.summary = 'Talk Like A Pirate'
|
9
|
+
s.description = 'Add a pirate translation layer to your Rails app! Talk, like a Pirate!'
|
10
|
+
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
# s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: talk_like_a_pirate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Hodges
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Add a pirate translation layer to your Rails app! Talk, like a Pirate!
|
15
|
+
email:
|
16
|
+
- sjhodges@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- lib/talk_like_a_pirate.rb
|
24
|
+
- lib/talk_like_a_pirate/pirate_booty.yml
|
25
|
+
- lib/talk_like_a_pirate/railties.rb
|
26
|
+
- lib/talk_like_a_pirate/tasks/pirate.rake
|
27
|
+
- talk_like_a_pirate.gemspec
|
28
|
+
homepage: https://github.com/stevehodges/
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.23
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Talk Like A Pirate
|
52
|
+
test_files: []
|