forked from nofxx/chronic18n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
require "chronic" | ||
require "yaml" | ||
|
||
require "chronic18n/translator" | ||
|
||
module Chronic18n | ||
|
||
def self.parse(txt, lang = nil) | ||
Chronic.parse(lang ? const_get(lang.capitalize).translate(txt) : txt) | ||
end | ||
|
||
def self.load_dic(lang) | ||
YAML.load(File.read(File.join(File.dirname(__FILE__), "chronic18n", "dics", "#{lang}.yml")))[lang] | ||
Chronic.parse(lang ? Translator.new(txt, lang).work : txt) | ||
end | ||
|
||
end | ||
|
||
require "chronic18n/pt" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Chronic18n | ||
|
||
|
||
class Translator | ||
|
||
def initialize(txt, lang) | ||
@txt = txt | ||
@dic = load_dic(lang) | ||
end | ||
|
||
def load_dic(lang) | ||
YAML.load(File.read(File.join(File.dirname(__FILE__), "dics", "#{lang}.yml")))[lang] | ||
end | ||
|
||
def work | ||
@txt.split(/\s/).map { |w| @dic[w] || w }.join(" ") | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe "Spanish" do | ||
|
||
it "should parse something" do | ||
Chronic18n.parse("lunes", :es).should be_a Time | ||
end | ||
|
||
it "should parse hour" do | ||
Chronic18n.parse("en 7 horas", :es).hour.should eql((Time.now.hour + 7) % 24) | ||
end | ||
|
||
it "should parse hour" do | ||
Chronic18n.parse("en 7 minutos", :es).min.should eql((Time.now.min + 7) % 60) | ||
end | ||
|
||
it "should parse sunday" do | ||
Chronic18n.parse("domingo", :es).wday.should eql(0) | ||
end | ||
|
||
it "should parse monday" do | ||
Chronic18n.parse("martes", :es).wday.should eql(2) | ||
end | ||
|
||
it "should parse month" do | ||
Chronic18n.parse("mayo 3", :es).month.should eql(5) | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
describe "Spanish" do | ||
|
||
it "should parse something" do | ||
Chronic18n.parse("sabato", :it).should be_a Time | ||
end | ||
|
||
it "should parse hour" do | ||
Chronic18n.parse("in 7 oras", :it).hour.should eql((Time.now.hour + 7) % 24) | ||
end | ||
|
||
it "should parse hour" do | ||
Chronic18n.parse("in 7 minutos", :it).min.should eql((Time.now.min + 7) % 60) | ||
end | ||
|
||
it "should parse sunday" do | ||
Chronic18n.parse("domenica", :it).wday.should eql(0) | ||
end | ||
|
||
it "should parse monday" do | ||
Chronic18n.parse("mercoledi", :it).wday.should eql(3) | ||
end | ||
|
||
it "should parse month" do | ||
Chronic18n.parse("maggio", :it).month.should eql(5) | ||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters