class PolyglotIos::Serializer::Source::Swift
Public Class Methods
new(translation_keys)
click to toggle source
# File lib/ios_polyglot_cli/serializers/sources/sources_serializer_swift.rb, line 10 def initialize(translation_keys) @translation_keys = translation_keys end
Public Instance Methods
build_translations()
click to toggle source
# File lib/ios_polyglot_cli/serializers/sources/sources_serializer_swift.rb, line 42 def build_translations() root_enum = TranslationEnum.new("Strings") @translation_keys.each do |translation_key| key_name = translation_key.name next if key_name.nil? components = key_name.split(".") root_enum.insert(components, key_name) end return root_enum end
render()
click to toggle source
# File lib/ios_polyglot_cli/serializers/sources/sources_serializer_swift.rb, line 14 def render() @root_enum = build_translations() ERB.new(template, nil, '-').result(binding) end
save(sources_path)
click to toggle source
# File lib/ios_polyglot_cli/serializers/sources/sources_serializer_swift.rb, line 55 def save(sources_path) FileUtils.mkdir_p sources_path unless File.exist? sources_path output_path = File.join(sources_path, "Strings.swift") File.write(output_path, render) end
template()
click to toggle source
# File lib/ios_polyglot_cli/serializers/sources/sources_serializer_swift.rb, line 19 def template() <<-TEMPLATE import Foundation // swiftlint:disable file_length type_body_length line_length superfluous_disable_command <%= @root_enum.serialized() %> public protocol StringsProtocol: RawRepresentable { var localized: String { get } func localized(with args: CVarArg...) -> String } public extension StringsProtocol where RawValue == String { var localized: String { return self.rawValue.localized } func localized(with args: CVarArg...) -> String { return String(format: self.rawValue.localized, arguments: args) } } TEMPLATE end