Class: Gherkin::I18n
- Inherits:
-
Object
- Object
- Gherkin::I18n
- Defined in:
- lib/gherkin/i18n.rb
Constant Summary collapse
- KEYWORD_KEYS =
%w{name native feature background scenario scenario_outline examples given when then and but}
- LANGUAGES =
YAML.load_file(File.dirname(__FILE__) + '/i18n.yml')
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
-
.all ⇒ Object
Used by code generators for other lexer tools like pygments lexer and textmate bundle.
- .get(key) ⇒ Object
-
.keyword_regexp(*keywords) ⇒ Object
Returns all keyword translations and aliases of
keywords
, escaped and joined with|
. - .languages ⇒ Object
Instance Method Summary collapse
- #adverbs ⇒ Object
- #and_keywords(space = true) ⇒ Object
- #background_keywords ⇒ Object
- #but_keywords(space = true) ⇒ Object
- #examples_keywords ⇒ Object
- #feature_keywords ⇒ Object
- #gwt_keywords ⇒ Object
- #incomplete? ⇒ Boolean
-
#initialize(key) ⇒ I18n
constructor
A new instance of I18n.
- #keywords(key, space = false) ⇒ Object
- #sanitized_key ⇒ Object
- #scenario_keywords ⇒ Object
- #scenario_outline_keywords ⇒ Object
- #step_keywords ⇒ Object
Constructor Details
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
40 41 42 |
# File 'lib/gherkin/i18n.rb', line 40 def key @key end |
Class Method Details
.all ⇒ Object
Used by code generators for other lexer tools like pygments lexer and textmate bundle
10 11 12 |
# File 'lib/gherkin/i18n.rb', line 10 def all LANGUAGES.keys.sort.map{|key| get(key)} end |
.get(key) ⇒ Object
14 15 16 |
# File 'lib/gherkin/i18n.rb', line 14 def get(key) languages[key] ||= new(key) end |
.keyword_regexp(*keywords) ⇒ Object
Returns all keyword translations and aliases of keywords
, escaped and joined with |
. This method is convenient for editor support and syntax highlighting engines for Gherkin, where there is typically a code generation tool to generate regular expressions for recognising the various I18n translations of Gherkin’s keywords.
The keywords
arguments can be one of :feature
, :background
, :scenario
, :scenario_outline
, :examples
, :step
.
29 30 31 32 33 34 35 36 37 |
# File 'lib/gherkin/i18n.rb', line 29 def keyword_regexp(*keywords) unique_keywords = all.map do |lang| keywords.map do |keyword| lang.__send__("#{keyword}_keywords".to_sym) end end unique_keywords.flatten.compact.sort.reverse.uniq.join('|').gsub(/\*/, '\*') end |
.languages ⇒ Object
18 19 20 |
# File 'lib/gherkin/i18n.rb', line 18 def languages @languages ||= {} end |
Instance Method Details
#adverbs ⇒ Object
98 99 100 101 |
# File 'lib/gherkin/i18n.rb', line 98 def adverbs # TODO: looks very similar to #step_keywords. Lose this? Where is it used from? %w{given when then and but}.map{|keyword| @keywords[keyword].split('|').map{|w| w.gsub(/[\s<']/, '')}}.flatten end |
#and_keywords(space = true) ⇒ Object
81 82 83 |
# File 'lib/gherkin/i18n.rb', line 81 def and_keywords(space=true) keywords('and', space) end |
#background_keywords ⇒ Object
69 70 71 |
# File 'lib/gherkin/i18n.rb', line 69 def background_keywords keywords('background') end |
#but_keywords(space = true) ⇒ Object
77 78 79 |
# File 'lib/gherkin/i18n.rb', line 77 def but_keywords(space=true) keywords('but', space) end |
#examples_keywords ⇒ Object
73 74 75 |
# File 'lib/gherkin/i18n.rb', line 73 def examples_keywords keywords('examples') end |
#feature_keywords ⇒ Object
57 58 59 |
# File 'lib/gherkin/i18n.rb', line 57 def feature_keywords keywords('feature') end |
#gwt_keywords ⇒ Object
89 90 91 |
# File 'lib/gherkin/i18n.rb', line 89 def gwt_keywords %w{given when then}.map{|key| keywords(key, true)}.flatten.uniq end |
#incomplete? ⇒ Boolean
53 54 55 |
# File 'lib/gherkin/i18n.rb', line 53 def incomplete? KEYWORD_KEYS.detect{|key| @keywords[key].nil?} end |
#keywords(key, space = false) ⇒ Object
93 94 95 96 |
# File 'lib/gherkin/i18n.rb', line 93 def keywords(key, space=false) raise "No #{key} in #{@keywords.inspect}" if @keywords[key].nil? @keywords[key].split('|').map{|kw| space ? keyword_space(kw) : kw} end |
#sanitized_key ⇒ Object
49 50 51 |
# File 'lib/gherkin/i18n.rb', line 49 def sanitized_key @key.gsub(/[\s-]/, '') end |
#scenario_keywords ⇒ Object
61 62 63 |
# File 'lib/gherkin/i18n.rb', line 61 def scenario_keywords keywords('scenario') end |
#scenario_outline_keywords ⇒ Object
65 66 67 |
# File 'lib/gherkin/i18n.rb', line 65 def scenario_outline_keywords keywords('scenario_outline') end |
#step_keywords ⇒ Object
85 86 87 |
# File 'lib/gherkin/i18n.rb', line 85 def step_keywords %w{given when then and but}.map{|key| keywords(key, true)}.flatten.uniq end |