Sha256: cdb89793bdda83342bce37f27f69a9bc7a9ea6f1101f7c5c67e5fca3eb5f423a

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 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.safe.capitalize -%>
<% bundle.tables.each do |table| -%>
<% class_name = bundle_name + table.name.safe -%>
    enum <%= class_name %>: String {
<% table.keys.each do |key| -%>
        case <%= key.safe %> = "<%= key %>"
<% end # keys -%>

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

        static let name = "<%= table.name %>"

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

        static var 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

2 entries across 2 versions & 1 rubygems

Version Path
xcmultilingual-0.2.3 lib/xcmultilingual/templates/swift.erb
xcmultilingual-0.2.2 lib/xcmultilingual/templates/swift.erb