Sha256: 1699291c35c05b1900ec53803b3db9a4378abccd03bc5a7eb0f8b4882563ef2b

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

//
//  <%= @filename %>
//  xcmultilingual
//
//  Created by xcmultilingual.
//
//

import Foundation

struct <%= @name %> {
<% @bundle_data.each do |bundle| -%>
<% nsbundle = bundle.name ? "Multilingual.bundle(\"#{bundle.relative_path}\")" : "NSBundle.mainBundle()" -%>
<% bundle_name = bundle.name.nil? ? "" : bundle.name.capitalize -%>
<% bundle.tables.each do |table| -%>
<% class_name = bundle_name + table.name -%>
    enum <%= class_name %>: String {
<% table.keys.each do |key| -%>
        case <%= key %> = "<%= key %>"
<% end # keys -%>

        func string() -> String {
            return NSLocalizedString(rawValue, tableName: "<%= table.name %>", bundle: <%= nsbundle %>, value: "\(rawValue)", comment: "")
        }

        static func keys() -> [String] {
            return ["<%= table.keys.join("\", \"") %>"]
        }

        static func localizations() -> [String] {
            return <%= class_name %>.keys().map { <%= class_name %>(rawValue: $0)!.string() }
        }
    }

<%- end # table -%>
<%- end # bundle -%>

    private static func bundle(relativePath: String) -> NSBundle {
        var components = (__FILE__ as String).pathComponents
        components.removeLast()
        let bundlePath = join("/", components) + "/" + relativePath
        return NSBundle(path: bundlePath) ?? NSBundle.mainBundle()
    }
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
xcmultilingual-0.1.6 lib/xcmultilingual/templates/swift.erb
xcmultilingual-0.1.5 lib/xcmultilingual/templates/swift.erb
xcmultilingual-0.1.4 lib/xcmultilingual/templates/swift.erb
xcmultilingual-0.1.3 lib/xcmultilingual/templates/swift.erb
xcmultilingual-0.1.2 lib/xcmultilingual/templates/swift.erb
xcmultilingual-0.1.1 lib/xcmultilingual/templates/swift.erb