-
Notifications
You must be signed in to change notification settings - Fork 83
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
11 changed files
with
177 additions
and
13 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Babelish | ||
VERSION = '0.3.2' | ||
VERSION = "0.3.2" | ||
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,46 @@ | ||
module Babelish | ||
class XcodeMacros | ||
attr_accessor :content, :table, :keys | ||
def initialize(table = "Localizable", keys = {}) | ||
@content = "" | ||
@table = table | ||
@keys = keys | ||
end | ||
|
||
def self.write_macros(file_path, table, keys) | ||
instance = XcodeMacros.new | ||
instance.process(table, keys) | ||
instance.write_content(file_path) | ||
end | ||
|
||
def process(table, keys) | ||
keys.each do |key| | ||
macro_name = "LS_#{key.upcase}" | ||
macro_name += "_#{table.upcase}" if table != "Localizable" | ||
macro_name.gsub!(' ', '') | ||
macro_name.gsub!('.', '_') | ||
macro_name.gsub!('-', '_') | ||
@content << String.new(<<-EOS) | ||
#define #{macro_name} NSLocalizedStringFromTable(@"#{key}",@"#{table}",@"") | ||
EOS | ||
end | ||
@content | ||
end | ||
|
||
def write_content(file_path) | ||
header = String.new(<<-EOS) | ||
// | ||
// file_path | ||
// | ||
// This file was generated by Babelish | ||
// | ||
// https://github.com/netbe/babelish | ||
// | ||
EOS | ||
header.gsub! "file_path", File.basename(file_path) | ||
file = File.new(file_path, "w") | ||
file.write header + @content | ||
file.close | ||
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
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,61 @@ | ||
require "test_helper" | ||
class TestXcodeMacros < Test::Unit::TestCase | ||
def test_process | ||
keys = ["login.title", "login.button"] | ||
table = "Localizable" | ||
xcode_macros = Babelish::XcodeMacros.new | ||
content = xcode_macros.process(table, keys) | ||
expected_output = String.new(<<-EOS) | ||
#define LS_LOGIN_TITLE NSLocalizedStringFromTable(@"login.title",@"Localizable",@"") | ||
#define LS_LOGIN_BUTTON NSLocalizedStringFromTable(@"login.button",@"Localizable",@"") | ||
EOS | ||
assert_equal expected_output, content | ||
end | ||
|
||
def test_write_macros_class_method | ||
keys = ["login.title", "login.button"] | ||
table = "Localizable" | ||
Babelish::XcodeMacros.write_macros("Babelish.h", table, keys) | ||
expected_output = String.new(<<-EOS) | ||
// | ||
// Babelish.h | ||
// | ||
// This file was generated by Babelish | ||
// | ||
// https://github.com/netbe/babelish | ||
// | ||
#define LS_LOGIN_TITLE NSLocalizedStringFromTable(@"login.title",@"Localizable",@"") | ||
#define LS_LOGIN_BUTTON NSLocalizedStringFromTable(@"login.button",@"Localizable",@"") | ||
EOS | ||
assert File.exists?("Babelish.h") | ||
result = File.read("Babelish.h") | ||
assert_equal expected_output, result | ||
#clean up | ||
system("rm -f ./Babelish.h") | ||
end | ||
|
||
|
||
def test_write_macros_process | ||
keys = ["login.title", "login.button"] | ||
table = "Localizable" | ||
macros = Babelish::XcodeMacros.new | ||
macros.process(table, keys) | ||
macros.write_content("Babelish.h") | ||
expected_output = String.new(<<-EOS) | ||
// | ||
// Babelish.h | ||
// | ||
// This file was generated by Babelish | ||
// | ||
// https://github.com/netbe/babelish | ||
// | ||
#define LS_LOGIN_TITLE NSLocalizedStringFromTable(@"login.title",@"Localizable",@"") | ||
#define LS_LOGIN_BUTTON NSLocalizedStringFromTable(@"login.button",@"Localizable",@"") | ||
EOS | ||
assert File.exists?("Babelish.h") | ||
result = File.read("Babelish.h") | ||
assert_equal expected_output, result | ||
#clean up | ||
system("rm -f ./Babelish.h") | ||
end | ||
end |