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
Cameron Dutro
committed
Sep 20, 2012
1 parent
4eb58f6
commit 710288e
Showing
38 changed files
with
300 additions
and
4 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
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
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,56 @@ | ||
# encoding: UTF-8 | ||
|
||
# Copyright 2012 Twitter, Inc | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
module TwitterCldr | ||
module Formatters | ||
class ListFormatter < Base | ||
|
||
def initialize(options = {}) | ||
@locale = TwitterCldr.convert_locale(extract_locale(options)) | ||
end | ||
|
||
def format(list) | ||
if resource.include?(list.size) | ||
compose(resource[list.size], list) | ||
else | ||
compose_list(list) | ||
end | ||
end | ||
|
||
protected | ||
|
||
def compose_list(list) | ||
result = compose(resource[:end], [list[-2], list[-1]]) | ||
|
||
# Ruby ranges don't support subtraction for some reason (eg. -3..-5). | ||
# Instead, we use a positive counter and negate it on array access. | ||
(3..list.size).each do |i| | ||
format_sym = i == list.size ? :start : :middle | ||
format_sym = :middle unless resource.include?(format_sym) | ||
result = compose(resource[format_sym], [list[-i], result]) | ||
end | ||
|
||
result | ||
end | ||
|
||
def compose(format, elements) | ||
elements.compact! | ||
|
||
if elements.size > 1 | ||
result = format.dup | ||
elements.size.times { |i| result.gsub!("{#{i}}", elements[i]) } | ||
result | ||
else | ||
elements[0] | ||
end | ||
end | ||
|
||
def resource | ||
@resource ||= TwitterCldr.get_locale_resource(@locale, :lists)[@locale][:lists] | ||
end | ||
|
||
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
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,7 @@ | ||
--- | ||
:af: | ||
:lists: | ||
2: ! '{0} en {1}' | ||
:end: ! '{0} en {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:ar: | ||
:lists: | ||
2: ! '{0} و {1}' | ||
:end: ! '{0}، و {1}' | ||
:middle: ! '{0}، {1}' | ||
:start: ! '{0}، {1}' |
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,7 @@ | ||
--- | ||
:ca: | ||
:lists: | ||
2: ! '{0} i {1}' | ||
:end: ! '{0} i {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:cs: | ||
:lists: | ||
2: ! '{0} a {1}' | ||
:end: ! '{0} a {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:da: | ||
:lists: | ||
2: ! '{0} og {1}' | ||
:end: ! '{0} og {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:de: | ||
:lists: | ||
2: ! '{0} und {1}' | ||
:end: ! '{0} und {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:el: | ||
:lists: | ||
2: ! '{0} και {1}' | ||
:end: ! '{0} και {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:en: | ||
:lists: | ||
2: ! '{0} and {1}' | ||
:end: ! '{0}, and {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:es: | ||
:lists: | ||
2: ! '{0} y {1}' | ||
:end: ! '{0} y {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:eu: | ||
:lists: | ||
2: ! '{0} eta {1}' | ||
:end: ! '{0} eta {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:fa: | ||
:lists: | ||
2: ! '{0} و {1}' | ||
:end: ! '{0}، و {1}' | ||
:middle: ! '{0}، {1}' | ||
:start: ! '{0}، {1}' |
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,7 @@ | ||
--- | ||
:fi: | ||
:lists: | ||
2: ! '{0} ja {1}' | ||
:end: ! '{0} ja {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:fil: | ||
:lists: | ||
2: ! '{0} at {1}' | ||
:end: ! '{0} at {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:fr: | ||
:lists: | ||
2: ! '{0} et {1}' | ||
:end: ! '{0} et {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:he: | ||
:lists: | ||
2: ! '{0} ו-{1}' | ||
:end: ! '{0} ו-{1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:hi: | ||
:lists: | ||
2: ! '{0} और {1}' | ||
:end: ! '{0}, और {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:hu: | ||
:lists: | ||
2: ! '{0} és {1}' | ||
:end: ! '{0} és {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:id: | ||
:lists: | ||
2: ! '{0} dan {1}' | ||
:end: ! '{0}, dan {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:it: | ||
:lists: | ||
2: ! '{0} e {1}' | ||
:end: ! '{0}, e {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:ja: | ||
:lists: | ||
2: ! '{0}、{1}' | ||
:end: ! '{0}、{1}' | ||
:middle: ! '{0}、{1}' | ||
:start: ! '{0}、{1}' |
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,7 @@ | ||
--- | ||
:ko: | ||
:lists: | ||
2: ! '{0} 및 {1}' | ||
:end: ! '{0} 및 {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:ms: | ||
:lists: | ||
2: ! '{0} dan {1}' | ||
:end: ! '{0}, dan {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:nb: | ||
:lists: | ||
2: ! '{0} og {1}' | ||
:end: ! '{0} og {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:nl: | ||
:lists: | ||
2: ! '{0} en {1}' | ||
:end: ! '{0} en {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:pl: | ||
:lists: | ||
2: ! '{0} i {1}' | ||
:end: ! '{0} i {1}' | ||
:middle: ! '{0}; {1}' | ||
:start: ! '{0}; {1}' |
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,7 @@ | ||
--- | ||
:pt: | ||
:lists: | ||
2: ! '{0} e {1}' | ||
:end: ! '{0} e {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:ru: | ||
:lists: | ||
2: ! '{0} и {1}' | ||
:end: ! '{0} и {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:sv: | ||
:lists: | ||
2: ! '{0} och {1}' | ||
:end: ! '{0} och {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:th: | ||
:lists: | ||
2: ! '{0}และ{1}' | ||
:end: ! '{0} และ{1}' | ||
:middle: ! '{0} {1}' | ||
:start: ! '{0} {1}' |
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,7 @@ | ||
--- | ||
:tr: | ||
:lists: | ||
2: ! '{0} ve {1}' | ||
:end: ! '{0} ve {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:uk: | ||
:lists: | ||
2: ! '{0} та {1}' | ||
:end: ! '{0} та {1}' | ||
:middle: ! '{0}, {1}' | ||
:start: ! '{0}, {1}' |
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,7 @@ | ||
--- | ||
:ur: | ||
:lists: | ||
2: ! '{0} اور {1}' | ||
:end: ! '{0}، اور {1}' | ||
:middle: ! '{0}، {1}' | ||
:start: ! '{0}، {1}' |
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,7 @@ | ||
--- | ||
:zh-Hant: | ||
:lists: | ||
2: ! '{0}和{1}' | ||
:end: ! '{0}和{1}' | ||
:middle: ! '{0}、{1}' | ||
:start: ! '{0}、{1}' |
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,7 @@ | ||
--- | ||
:zh: | ||
:lists: | ||
2: ! '{0}和{1}' | ||
:end: ! '{0}和{1}' | ||
:middle: ! '{0}、{1}' | ||
:start: ! '{0}、{1}' |