Skip to content

Commit

Permalink
Implement i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
flbulgarelli committed Apr 5, 2023
1 parent f7c5865 commit 3061e51
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/js/edlhighligh.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ hljs.registerLanguage('edl', () => {
return {
k: {
keyword: "count except in like unlike something somewhere expectation that through with within",
literal: "anything false logic math nil self true literal nonliteral",
literal: "anything false logic math nil self true literal nonliteral anystring anynumber",
built_in: "and or not"
},
c: [
Expand Down
2 changes: 2 additions & 0 deletions gem/lib/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ en:
with_char: ' with character <code>%{value}</code>'
with_false: ' with value <code>%{keyword_False}</code>'
with_literal: ' with a literal value'
with_any_string: ' with a string literal'
with_any_number: ' with a number literal'
with_logic: ' with a boolean expression'
with_math: ' with a math expression'
with_nil: ' with <code>%{keyword_Nil}</code>'
Expand Down
2 changes: 2 additions & 0 deletions gem/lib/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ es:
with_char: ' con el carácter <code>%{value}</code>'
with_false: ' con el valor <code>%{keyword_False}</code>'
with_literal: ' con un valor literal'
with_any_string: ' con un string literal'
with_any_number: ' con un número literal'
with_logic: ' con una expresión booleana'
with_math: 'con una expresión matemática'
with_nil: ' con <code>%{keyword_Nil}</code>'
Expand Down
2 changes: 2 additions & 0 deletions gem/lib/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pt:
with_char: ' com o caractere <code>%{value}</code>'
with_false: ' com o valor <code>%{keyword_False}</code>'
with_literal: ' com um valor literal'
with_any_string: ' com uma string literal'
with_any_number: ' com um número literal'
with_logic: ' com uma expressão booleana'
with_math: ' com uma expressão matemática'
with_nil: ' com <code>%{keyword_Nil}</code>'
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>WithAnything|WithLiteral|WithNonliteral|WithLogic|WithMath|WithFalse|WithNil|WithTrue) |
:(?<matcher>WithAnything|WithLiteral|WithNonliteral|WithAnyString|WithAnyNumber|WithLogic|WithMath|WithFalse|WithNil|WithTrue) |
:(?<matcher>WithReference|WithChar|WithNumber|WithString|WithSymbol):(?<value>[^:]+) |
:(?<target>[^:]+)(:(?<matcher>[^:]+)(:(?<value>[^:]+))?)?
)?$}.gsub(/\s/, '')
Expand Down
3 changes: 2 additions & 1 deletion gem/lib/mulang/inspection/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Mulang::Inspection::Matcher
WithAnything WithChar WithFalse WithLiteral
WithLogic WithMath WithNil WithNonliteral
WithNumber WithReference WithString
WithSymbol WithTrue)
WithSymbol WithTrue
WithAnyString WithAnyNumber)

attr_accessor :type, :value

Expand Down
8 changes: 8 additions & 0 deletions gem/spec/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def expectation(binding, inspection)
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') }
it { expect(expectation('*', 'CallsSetAt:WithReference:x').translate).to eq('solution must use <code>[]=</code> with <code>x</code>') }

it { expect(expectation('*', 'CallsPlus:WithAnyString').translate).to eq('solution must use <code>+</code> with a string literal') }
it { expect(expectation('*', 'CallsPlus:WithAnyNumber').translate).to eq('solution must use <code>+</code> with a number literal') }
end
end

Expand All @@ -94,6 +97,8 @@ def expectation(binding, inspection)

it { expect(expectation('*', 'CallsSlice:WithReference:nomes').translate :Python).to eq('a solução deve utilizar <code>[:]</code> com <code>nomes</code>') }

it { expect(expectation('*', 'CallsPlus:WithAnyString').translate).to eq('a solução deve utilizar <code>+</code> com uma string literal') }
it { expect(expectation('*', 'CallsPlus:WithAnyNumber').translate).to eq('a solução deve utilizar <code>+</code> com um número literal') }
end

context 'es locale' do
Expand Down Expand Up @@ -121,6 +126,9 @@ def expectation(binding, inspection)

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:WithReference:y').translate :JavaScript).to eq('la solución debe usar <code>length</code> con <code>y</code>') }

it { expect(expectation('*', 'CallsPlus:WithAnyString').translate).to eq('la solución debe usar <code>+</code> con un string literal') }
it { expect(expectation('*', 'CallsPlus:WithAnyNumber').translate).to eq('la solución debe usar <code>+</code> con un número literal') }
end

describe 'custom expectations' do
Expand Down
2 changes: 2 additions & 0 deletions gem/spec/inspection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
it { expect(Mulang::Inspection.parse("Assigns:x")).to json_like(type: 'Assigns', negated: false, target: {type: :unknown, value: 'x'}) }
it { expect(Mulang::Inspection.parse("Assigns:WithFalse")).to json_like(type: 'Assigns', negated: false, matcher: {type: :with_false }) }
it { expect(Mulang::Inspection.parse("Assigns:WithNumber:2")).to json_like(type: 'Assigns', negated: false, matcher: {type: :with_number, value: "2" }) }
it { expect(Mulang::Inspection.parse("Assigns:WithAnyNumber")).to json_like(type: 'Assigns', negated: false, matcher: {type: :with_any_number }) }
it { expect(Mulang::Inspection.parse("Assigns:WithAnyString")).to json_like(type: 'Assigns', negated: false, matcher: {type: :with_any_string }) }

it { expect(Mulang::Inspection.parse("Returns:WithFalse")).to json_like(type: 'Returns', negated: false, matcher: {type: :with_false }) }
it { expect(Mulang::Inspection.parse("Returns:WithNil")).to json_like(type: 'Returns', negated: false, matcher: {type: :with_nil }) }
Expand Down
12 changes: 6 additions & 6 deletions spec/LiteralSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ spec = do
isNonliteral (MuNumber 4) `shouldBe` False

it "works with anynumber and anystring" $ do
isAnyNumber MuNil `shouldBe` False
isAnyNumber (MuString "Nil") `shouldBe` False
isAnyNumber MuTrue `shouldBe` False
isAnyNumber (MuNumber 4) `shouldBe` True

isAnyString MuNil `shouldBe` False
isAnyString (MuString "Nil") `shouldBe` True
isAnyString MuTrue `shouldBe` False
isAnyString (MuNumber 4) `shouldBe` False
isAnyString (MuNumber 4) `shouldBe` False

isAnyNumber MuNil `shouldBe` False
isAnyNumber (MuString "Nil") `shouldBe` False
isAnyNumber MuTrue `shouldBe` False
isAnyNumber (MuNumber 4) `shouldBe` True
2 changes: 1 addition & 1 deletion src/Language/Mulang/Edl/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ tokens :-
"math" { symbolToken TMath }
"nil" { symbolToken TNil }
"nonliteral" { symbolToken TNonliteral }
"anynumber" { symbolToken TAnyNumber }
"anystring" { symbolToken TAnyString }
"anynumber" { symbolToken TAnyNumber }
"not" { symbolToken TNot }
"or" { symbolToken TOr }
"self" { symbolToken TSelf }
Expand Down
4 changes: 2 additions & 2 deletions src/Language/Mulang/Edl/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ Clause : number { IsNumber . numberValue $ $1 }
| math { IsMath }
| nil { IsNil }
| nonliteral { IsNonliteral }
| anynumber { IsAnyNumber }
| anystring { IsAnyString }
| anynumber { IsAnyNumber }
| self { IsSelf }
| true { IsTrue }
| something that openParen TopQuery closeParen { That $4 }
Expand Down Expand Up @@ -226,8 +226,8 @@ m TLogic = "logic is not expected here"
m TMath = "math is not expected here"
m TNil = "nil is not expected here"
m TNonliteral = "nonliteral is not expected here"
m TAnyNumber = "anynumber is not expected here"
m TAnyString = "anystring is not expected here"
m TAnyNumber = "anynumber is not expected here"
m TNot = "not is not expected here"
m TOpenParen = "Unexpected )"
m TOr = "or is not expected here"
Expand Down

0 comments on commit 3061e51

Please sign in to comment.