Skip to content

Localization Events

Will Powell edited this page Dec 27, 2017 · 1 revision

One of the key features of LocalizationKit are the events. These control the delivery of localizations in realtime. LocalizationKit uses the notification centre to distribute these events. This wiki page covers the event used.

All Change Event - (Localization.ALL_CHANGE)

This event is triggered when all localizations have changed. This occurs after load from Localizationkit.com initially, load from the local cache or if the LocalizationKit language is changed (which causes a reload from LocalizationKit.com).

To listen for this event you can use the following Notification observer addition:

NotificationCenter.default.addObserver(self, selector: #selector([[YOUR_SELECTOR]]), name: Localization.ALL_CHANGE, object: nil)

Individual Key Change

If you want to detect an individual key changing which is caused when it is changed online or from another app with inline editor you can do this with this event. To get the event for the particular key use the following code:

let keyUpdateEvent = Localization.localizationEvent(localizationKey: "[[LOCALIZATION_KEY]]")

Combining this you can then get an event trigger for this key update as follows:

let keyUpdateEvent = Localization.localizationEvent(localizationKey: "[[LOCALIZATION_KEY]]")
NotificationCenter.default.addObserver(self, selector: #selector(keyUpdateEventHandler), name: keyUpdateEvent, object: nil)

@objc public func keyUpdateEventHandler() {
   print("Key Updated")
}

Individual Key Highlight

As there is also a highlight event on the web UI which is designed to show a user where a Key is being used. This also triggers an event. Much like a localization event you can get the highlight event for the particular key use the following code:

let keyUpdateEvent = Localization. highlightEvent(localizationKey: "[[LOCALIZATION_KEY]]")

Combining this you can then get an event trigger for this key update as follows:

let keyHighlightEvent = Localization. highlightEvent(localizationKey: "[[LOCALIZATION_KEY]]")
NotificationCenter.default.addObserver(self, selector: #selector(highlightEventHandler), name: keyHighlightEvent, object: nil)

@objc public func highlightEventHandler() {
   print("Key highlighted")
}