EmbeddedStringsKit

0.3.0

FluidGroup/EmbeddedStringsKit

What's New

0.3.0

2024-05-09T04:20:25Z

What's Changed

New Contributors

  • @muukii made their first contribution in #1

Full Changelog: 0.2.0...0.3.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: Mon Oct 21 2024 14:22:12 GMT-0900 (Hawaii-Aleutian Daylight Time)