explicitClick to confirm you are 18+

How to manage Localized Strings in your Project

MariusMar 8, 2020, 4:30:08 PM
thumb_upthumb_downmore_vert

We want to create for each ViewController a Enum as collection for our Localized String Keys, this will look like that.



we want all strings in one file for example (Strings.swift) in this file we can add strings via extensions to our ViewControllers

For a better structure and to solve name conflicts we need a namespace for each ViewController. So wee need a other Protocol let us call this StringLocalizeable.



Now we have to implement in our Strings Enum the StringLocalizeable Protocol we need changes in the PorfileViewController and in the Strings Protocol.


Strings need as RawValue Type a String


add a different namespace for each ViewController Strings

Our Localizable.strings looks with namespace like that


Now we can use the Strings Enum in our ProfileViewController to get the Localized Strings. You can also create a global Strings Enum without namespace for global Strings, but than you need as prefix the project name (package name) !!!


we can use also arguments for our strings