EmbeddedStringsKit

0.2.0

FluidGroup/EmbeddedStringsKit

What's New

0.2.0

2022-06-30T14:30:18Z

Full Changelog: 0.1.0...0.2.0

EmbeddedStringsKit

Representation localized string in code

Usage

public struct LocalizedStringsTrait: LocalizedStringsTraitType {

  public static let instance = LocalizedStringsTrait()

  public var defaultLanguage: LocalizedStringsLanguage {
    return ja
  }

  public let ja = LocalizedStringsLanguage(identifier: "ja")
  public let en = LocalizedStringsLanguage(identifier: "en")
}

/**
 Embedding Localized Strings
 */
public typealias Strings = LocalizedStrings<LocalizedStringsTrait>

extension Strings {

  /// Creates an instance of localizable strings
  ///
  /// You may use `{{ name }}` token to interpolate strings.
  ///
  /// - Parameter ja:
  public init(
    ja: StaticString,
    en: StaticString
  ) {

    var instance = Self.makeDraft()
    instance.ja = ja
    instance.en = en
    self = instance

  }
}
let localizedText = Strings(
  ja: "こんにちは {{name}} です。",
  en: "Hello, I'm {{name}}."
  )
  .string(parameters: ["name" : "John"])

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Mar 12 2024 18:24:18 GMT-0900 (Hawaii-Aleutian Daylight Time)