-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tasks-for-translation-cleanup' into develop
- Loading branch information
Showing
4 changed files
with
151 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# -*- encoding : utf-8 -*- | ||
module AlaveteliGetText | ||
class FuzzyCleaner | ||
def clean_po(input) | ||
lines = input.split("\n") | ||
|
||
lines.each_with_index do |line, index| | ||
match = /^msgid "(.*)"/.match(line) | ||
if $1 | ||
if /^#, fuzzy/.match(lines[index-1]) | ||
# one line msgstr | ||
if /^msgstr "(.+)"/.match(lines[index+1]) | ||
lines[index+1] = "msgstr \"\"" | ||
lines.delete_at(index-1) | ||
end | ||
# multiline msgstr | ||
if /^msgstr ""/.match(lines[index+1]) | ||
while /^".+"/.match(lines[index+2]) | ||
lines.delete_at(index+2) | ||
end | ||
lines.delete_at(index-1) | ||
end | ||
# plural msgstr | ||
if /^msgid_plural "(.*)"/.match(lines[index+1]) | ||
offset = 0 | ||
while /^msgstr\[#{offset}\] "(.*)"/.match(lines[index+2+offset]) | ||
lines[index+2+offset] = "msgstr[#{offset}] \"\"" | ||
offset += 1 | ||
end | ||
lines.delete_at(index-1) | ||
end | ||
end | ||
end | ||
end | ||
|
||
lines.join("\n") << "\n" | ||
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,100 @@ | ||
# -*- encoding : utf-8 -*- | ||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') | ||
|
||
describe AlaveteliGetText::FuzzyCleaner do | ||
|
||
describe '#clean_po' do | ||
|
||
it 'removes the fuzzy marker and msgstr from a single-line msgstr' do | ||
input = <<-EOF.strip_heredoc | ||
msgid "Some msgid" | ||
msgstr "Translated msgstr" | ||
#, fuzzy | ||
msgid "Fuzzy msgid" | ||
msgstr "Fuzzy translation" | ||
msgid "Another msgid" | ||
msgstr "Another translated msgstr" | ||
EOF | ||
|
||
expected = <<-EOF.strip_heredoc | ||
msgid "Some msgid" | ||
msgstr "Translated msgstr" | ||
msgid "Fuzzy msgid" | ||
msgstr "" | ||
msgid "Another msgid" | ||
msgstr "Another translated msgstr" | ||
EOF | ||
|
||
expect(subject.clean_po(input)).to eq(expected) | ||
end | ||
|
||
it 'removes the fuzzy marker and msgstr from a multi-line msgstr' do | ||
input = <<-EOF.strip_heredoc | ||
msgid "Some msgid" | ||
msgstr "Translated msgstr" | ||
#, fuzzy | ||
msgid "Multi-line fuzzy" | ||
msgstr "" | ||
"Fuzzy translation…" | ||
"…over several " | ||
"lines" | ||
msgid "Another msgid" | ||
msgstr "Another translated msgstr" | ||
EOF | ||
|
||
expected = <<-EOF.strip_heredoc | ||
msgid "Some msgid" | ||
msgstr "Translated msgstr" | ||
msgid "Multi-line fuzzy" | ||
msgstr "" | ||
msgid "Another msgid" | ||
msgstr "Another translated msgstr" | ||
EOF | ||
|
||
expect(subject.clean_po(input)).to eq(expected) | ||
end | ||
|
||
it 'removes the fuzzy marker and msgstrs from a plural msgstr' do | ||
input = <<-EOF.strip_heredoc | ||
msgid "Some msgid" | ||
msgstr "Translated msgstr" | ||
#, fuzzy | ||
msgid "Fuzzy msgid" | ||
msgid_plural "Plural fuzzy" | ||
msgstr[0] "Fuzzy translation" | ||
msgstr[1] "Plural translation" | ||
msgstr[2] "Further plural" | ||
msgid "Another msgid" | ||
msgstr "Another translated msgstr" | ||
EOF | ||
|
||
expected = <<-EOF.strip_heredoc | ||
msgid "Some msgid" | ||
msgstr "Translated msgstr" | ||
msgid "Fuzzy msgid" | ||
msgid_plural "Plural fuzzy" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
msgstr[2] "" | ||
msgid "Another msgid" | ||
msgstr "Another translated msgstr" | ||
EOF | ||
|
||
expect(subject.clean_po(input)).to eq(expected) | ||
end | ||
|
||
end | ||
|
||
end |