Skip to content

Commit

Permalink
Extend translation capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
flbulgarelli committed Feb 4, 2023
1 parent 7095aea commit 0b7d41b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion gem/lib/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ en:
must_not: must not
must: must
solution: solution
with_anything: ' with some expression'
with_char: ' with character <code>%{value}</code>'
with_false: ' with value <code>%{keyword_False}</code>'
with_literal: ' with a literal value'
with_logic: ' with a boolean expression'
with_math: ' with a math expression'
with_nil: ' with <code>%{keyword_Nil}</code>'
with_nonliteral: ' with a non-literal expresson'
with_nonliteral: ' with a non-literal expression'
with_number: ' with number <code>%{value}</code>'
with_string: ' with string <code>%{value}</code>'
with_symbol: ' with symbol <code>%{value}</code>'
Expand Down
1 change: 1 addition & 0 deletions gem/lib/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ es:
must_not: no debe
must: debe
solution: la solución
with_anything: ' con alguna expresión'
with_char: ' con el carácter <code>%{value}</code>'
with_false: ' con el valor <code>%{keyword_False}</code>'
with_literal: ' con un valor literal'
Expand Down
1 change: 1 addition & 0 deletions gem/lib/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pt:
must_not: 'não deve'
must: 'deve'
solution: 'a solução'
with_anything: ' com alguma expressão'
with_char: ' com o caractere <code>%{value}</code>'
with_false: ' com o valor <code>%{keyword_False}</code>'
with_literal: ' com um valor literal'
Expand Down
2 changes: 1 addition & 1 deletion gem/lib/mulang/inspection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def as_json(*args)
^(?<negation>Not:)?
(?<type>[^:]+)
(
:(?<matcher>WithLiteral|WithNonliteral|WithLogic|WithMath|WithFalse|WithNil|WithTrue) |
:(?<matcher>WithAnything|WithLiteral|WithNonliteral|WithLogic|WithMath|WithFalse|WithNil|WithTrue) |
:(?<matcher>WithChar|WithNumber|WithString|WithSymbol):(?<value>[^:]+) |
:(?<target>[^:]+)(:(?<matcher>[^:]+)(:(?<value>[^:]+))?)?
)?$}.gsub(/\s/, '')
Expand Down
5 changes: 4 additions & 1 deletion gem/lib/mulang/inspection/matcher.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
class Mulang::Inspection::Matcher
include Mulang::Inspection::Compacted

TYPES = %w(WithChar WithFalse WithLiteral WithLogic WithMath WithNil WithNonliteral WithNumber WithString WithSymbol WithTrue)
TYPES = %w(
WithAnything WithChar WithFalse WithLiteral WithLogic
WithMath WithNil WithNonliteral WithNumber WithString
WithSymbol WithTrue)

attr_accessor :type, :value

Expand Down
9 changes: 8 additions & 1 deletion gem/spec/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def expectation(binding, inspection)
it { expect(expectation('*', "Returns:WithFalse").translate).to eq('solution must return with value <code>false</code>') }
it { expect(expectation('*', "UsesRepeat:WithMath").translate).to eq('solution must use <code>repeat</code> with a math expression') }
it { expect(expectation('*', "Calls:g:WithLiteral").translate).to eq('solution must use <code>g</code> with a literal value') }
it { expect(expectation('*', "Calls:g:WithNonliteral").translate).to eq('solution must use <code>g</code> with a non-literal expresson') }
it { expect(expectation('*', "Calls:g:WithNonliteral").translate).to eq('solution must use <code>g</code> with a non-literal expression') }
it { expect(expectation('*', "Calls:g:WithLogic").translate).to eq('solution must use <code>g</code> with a boolean expression') }
it { expect(expectation('*', "DeclaresVariable:x:WithNumber:4").translate).to eq('solution must declare a variable <code>x</code> with number <code>4</code>') }
it { expect(expectation('*', "Assigns:x:WithSymbol:bar").translate).to eq('solution must assign <code>x</code> with symbol <code>bar</code>') }
Expand Down Expand Up @@ -68,6 +68,10 @@ def expectation(binding, inspection)
it { expect(expectation('*', 'UsesBitwiseXor').translate).to eq('solution must use <code>^</code>') }
it { expect(expectation('*', 'UsesBitwiseLeftShift').translate).to eq('solution must use <code>&lt;&lt;</code>') }
it { expect(expectation('*', 'UsesBitwiseRightShift').translate).to eq('solution must use <code>&gt;&gt;</code>') }

it { expect(expectation('*', 'CallsSetAt').translate).to eq('solution must use <code>[]=</code>') }
it { expect(expectation('*', 'CallsSetAt:WithAnything').translate).to eq('solution must use <code>[]=</code> with some expression') }
it { expect(expectation('*', 'CallsSetAt:WithLiteral').translate).to eq('solution must use <code>[]=</code> with a literal value') }
end
end

Expand Down Expand Up @@ -111,6 +115,9 @@ def expectation(binding, inspection)

it { expect(expectation('foo', 'HasIf').translate(keyword_If: 'si')).to eq('<code>foo</code> debe usar <code>si</code>') }
it { expect(expectation('foo', 'HasIf').translate(keyword_Repeat: 'repetir')).to eq('<code>foo</code> debe usar <code>if</code>') }

it { expect(expectation('*', 'CallsSize:WithNonliteral').translate :Python).to eq('la solución debe usar <code>len</code> con una expresión no literal') }
it { expect(expectation('*', 'CallsSize:WithNonliteral').translate :JavaScript).to eq('la solución debe usar <code>length</code> con una expresión no literal') }
end

describe 'custom expectations' do
Expand Down
6 changes: 4 additions & 2 deletions generators/tokens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ def operators_translations_yml(operators, use)
%Q{
mulang:
inspection:
#{operators.map do |it|
" Uses#{it}: '%{binding} %{must} #{use} <code>%{operator_#{it}}</code>'"
#{operators.flat_map do |it| [
" Uses#{it}: '%{binding} %{must} #{use} <code>%{operator_#{it}}</code>'",
" Calls#{it}: '%{binding} %{must} #{use} <code>%{operator_#{it}}</code>%{matching}'"
]
end.join("\n")}}
end

Expand Down

0 comments on commit 0b7d41b

Please sign in to comment.