Skip to content

📦 Contains a few extensions for looking up localized strings prefixed with current class name.

Notifications You must be signed in to change notification settings

hoereth/TranslationExtensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 TranslationExtensions

This Swift-Package contains a few extensions for looking up localized strings prefixed with current class name.

Examples

Basic Example

Just make your class conform to "Translatable" protocol to extend it with a few basic translation functions.

import TranslationExtensions
...
class SomeClass: Translatable {
  ...
  // localized string with key "SomeClass.myKey"
  let translation1 = self.translateKey("myKey")
  
  // localized formatted string with key "SomeClass.otherKey"
  let translation2 = self.translateFormatKey("otherKey", "world")
}

ViewController Example

Every ViewController in your project will automatically have a few translation functions, once you import "TranslationExtensions".

import TranslationExtensions
...
class TestController: UIViewController {
  @IBOutlet weak var button: UIButton!
  ...
  override func viewDidLoad() {
     super.viewDidLoad()
  
     // sets title to localized string with key: "TestController.title"
     self.translateTitle()
     
     // transforms button title from title value "dummyTitle" to
     // localized string with key: "TestController.dummyTitle"
     self.translateButton(button)
  }
}

About

📦 Contains a few extensions for looking up localized strings prefixed with current class name.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages