talk_like_a_pirate 0.0.2 → 0.0.3
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/README.md +50 -0
- data/lib/talk_like_a_pirate.rb +27 -11
- data/talk_like_a_pirate.gemspec +1 -1
- metadata +2 -1
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
Ahoy, mateys!
|
2
|
+
=====
|
3
|
+
|
4
|
+
Delight yer users with the flavor of the high seas!
|
5
|
+
|
6
|
+
Add a pirate translation layer to your Rails app! Talk, like a Pirate!
|
7
|
+
|
8
|
+
Translate English to Pirate on the fly!
|
9
|
+
----
|
10
|
+
|
11
|
+
TalkLikeAPirate.translate("Today is a good day to die")
|
12
|
+
=> "Today is a jolly good day t' die"
|
13
|
+
|
14
|
+
If you pass in a sentence (and have a bit o' luck), you might get some extra piratey flavoring sprinkled on the end of your string!
|
15
|
+
|
16
|
+
Build a Pirate locale layer for i18n
|
17
|
+
----
|
18
|
+
Use i18n? The pirate rake task can generate a pirate locale (arr, by default) based on your English locale files.
|
19
|
+
|
20
|
+
rake pirate:translate["config/locales"]
|
21
|
+
|
22
|
+
It'll iterate through all of your en.yml files in that location and build a pirate version. You can also specify a specific en.yml file to translate just that file!
|
23
|
+
|
24
|
+
Config
|
25
|
+
----
|
26
|
+
The pirate dictionary is fairly generic. You my have domain-specific lingo you think would be fucking hillarious in pirate. So, add on to the dictionary!
|
27
|
+
|
28
|
+
Add a config file at
|
29
|
+
|
30
|
+
config/pirate_booty.yml
|
31
|
+
|
32
|
+
And format it like so (all keys are optional):
|
33
|
+
|
34
|
+
locale: pirate # This defaults to arr, but you can override it if you'd prefer a different locale string!
|
35
|
+
dictionary:
|
36
|
+
computer: voodoo
|
37
|
+
bill: debt
|
38
|
+
policies: creeds
|
39
|
+
inventory: treasure chest
|
40
|
+
|
41
|
+
pirate_flavor: # the flavoring occasionally added to the ends of sentences
|
42
|
+
- "T' Davy Jones' locker wit ya"
|
43
|
+
|
44
|
+
Contributions
|
45
|
+
=====
|
46
|
+
Feel free to write specs, add to the standard dictionary, etc. Submit a pull request and we'll see what happens!
|
47
|
+
|
48
|
+
Credits
|
49
|
+
=====
|
50
|
+
Copyright (c) 2013, developed and maintained by Steve Hodges, and is released under the open MIT Licence
|
data/lib/talk_like_a_pirate.rb
CHANGED
@@ -17,16 +17,24 @@ private #####################################################################
|
|
17
17
|
def self.translate_string(me_string)
|
18
18
|
me_string.split(/ /).map do |word|
|
19
19
|
capitalized = (word.slice(0,1) == word.slice(0,1).upcase)
|
20
|
-
|
21
|
-
|
22
|
-
word = dictionary[word.downcase.singularize]
|
23
|
-
word = pluralized ? word.pluralize : word
|
24
|
-
word = capitalized ? capitalize_first(word) : word
|
25
|
-
end
|
26
|
-
word
|
20
|
+
word = rails_present? ? piratize_with_pluralization(word) : piratize(word)
|
21
|
+
capitalized ? capitalize_first(word) : word
|
27
22
|
end.join(" ")
|
28
23
|
end
|
29
24
|
|
25
|
+
def self.piratize_with_pluralization(word)
|
26
|
+
pluralized = word.pluralize == word
|
27
|
+
if dictionary.has_key?(word.downcase.singularize)
|
28
|
+
word = dictionary[word.downcase.singularize]
|
29
|
+
word = pluralized ? word.pluralize : word
|
30
|
+
end
|
31
|
+
word
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.piratize(word)
|
35
|
+
dictionary.has_key?(word.downcase) ? dictionary[word.downcase] : word
|
36
|
+
end
|
37
|
+
|
30
38
|
def self.prepare_original_sentence(sentence)
|
31
39
|
sentence.gsub!(/\.\z/, "")
|
32
40
|
sentence = sentence + "." if sentence.match(/\w\z/)
|
@@ -46,11 +54,11 @@ private #####################################################################
|
|
46
54
|
end
|
47
55
|
|
48
56
|
def self.sprinklings_of_flavor
|
49
|
-
@@fill ||= (config["pirate_flavor"] << local_flavor).compact
|
57
|
+
@@fill ||= (config["pirate_flavor"] << local_flavor).compact.flatten
|
50
58
|
end
|
51
59
|
|
52
60
|
def self.config
|
53
|
-
@@config ||= YAML
|
61
|
+
@@config ||= YAML::load_file(File.dirname(__FILE__) + "/talk_like_a_pirate/pirate_booty.yml")
|
54
62
|
end
|
55
63
|
|
56
64
|
def self.local_dictionary
|
@@ -62,7 +70,7 @@ private #####################################################################
|
|
62
70
|
end
|
63
71
|
|
64
72
|
def self.local_config
|
65
|
-
@@local_configs ||= YAML
|
73
|
+
@@local_configs ||= YAML::load_file("#{Rails.root.to_s}/config/pirate_booty.yml") rescue {}
|
66
74
|
end
|
67
75
|
|
68
76
|
def self.capitalize_first(string)
|
@@ -71,6 +79,14 @@ private #####################################################################
|
|
71
79
|
string.slice(0,1).capitalize + string.slice(1..-1)
|
72
80
|
end
|
73
81
|
|
82
|
+
def self.rails_present?
|
83
|
+
Object.const_defined? :Rails
|
84
|
+
end
|
85
|
+
|
74
86
|
end
|
75
87
|
|
76
|
-
|
88
|
+
if Object.const_defined? :Rails
|
89
|
+
require "talk_like_a_pirate/railties"
|
90
|
+
else
|
91
|
+
require "yaml"
|
92
|
+
end
|
data/talk_like_a_pirate.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'talk_like_a_pirate'
|
4
|
-
s.version = '0.0.
|
4
|
+
s.version = '0.0.3'
|
5
5
|
s.authors = ['Steve Hodges']
|
6
6
|
s.email = ['sjhodges@gmail.com']
|
7
7
|
s.homepage = 'https://github.com/stevehodges/talk_like_a_pirate'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: talk_like_a_pirate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -20,6 +20,7 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- Gemfile
|
22
22
|
- Gemfile.lock
|
23
|
+
- README.md
|
23
24
|
- lib/talk_like_a_pirate.rb
|
24
25
|
- lib/talk_like_a_pirate/pirate_booty.yml
|
25
26
|
- lib/talk_like_a_pirate/railties.rb
|