Slide 1

Slide 1 text

Swift Scripting On the rescue of Localizable strings files management on iOS Cocoaheads Paris - April 2019 @jcsorin

Slide 2

Slide 2 text

Adopt refurbished products, only by certified professionals. All things equal, except the price.  www.backmarket.com

Slide 3

Slide 3 text

fuck new.

Slide 4

Slide 4 text

Swift Scripting? !

Slide 5

Slide 5 text

Manage localization efficiently

Slide 6

Slide 6 text

Our technical context 1- SwiftGen 2- lokalise.co 3- Localization.framework

Slide 7

Slide 7 text

1/3 - Use SwiftGen for safer translation code https://github.com/SwiftGen/SwiftGen

Slide 8

Slide 8 text

2/3: Managing strings translations with lokalise.co + the SDK (OTA updates) https://lokalise.co

Slide 9

Slide 9 text

2/3: Managing strings translations with lokalise.co + the SDK (OTA updates) https://lokalise.co

Slide 10

Slide 10 text

2/3 - Link Lokalise with SwiftGen

Slide 11

Slide 11 text

3/3: Create a dedicated Localization.framework for your app

Slide 12

Slide 12 text

+ + = ❤

Slide 13

Slide 13 text

Two issues

Slide 14

Slide 14 text

Issue N°1: lokalise.co strings up to date • What about our string code integration with SwiftGen? • What about strings fall-back? • What about first launch? • If there is no network at launch? • What if lokalise.co is down?

Slide 15

Slide 15 text

Easy: download the last files versions from lokalise.co

Slide 16

Slide 16 text

Manually?

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Let's make a Swift script!

Slide 19

Slide 19 text

6 Steps 1. Make shell commands call possible 2. Create the API download calls with URLSession & Codable ⬇ 3. Multi-languages support ( 4. Create the zip unarchiving and copy files code 5. Use the command line parameters 6. Clean & make it beautiful

Slide 20

Slide 20 text

1/6 - Make shell commands call possible

Slide 21

Slide 21 text

2/6 - Create the API download calls with URLSession & Codable ⬇

Slide 22

Slide 22 text

2/6 - Create the API download calls with URLSession & Codable ⬇

Slide 23

Slide 23 text

2/6 - Create the API download calls with URLSession & Codable ⬇

Slide 24

Slide 24 text

3/6 - Multi-languages support (

Slide 25

Slide 25 text

4/6 - Create the zip unarchiving and copy files code

Slide 26

Slide 26 text

5/6 - Use the command line parameters

Slide 27

Slide 27 text

6/6 - Clean & make it beautiful

Slide 28

Slide 28 text

Issue 1: ✅ lokalise.co download now automated

Slide 29

Slide 29 text

Issue N°2: What about plurals? • There is no official SwiftGen template (yet) • Stringsdict rocks • Yes, we love SwiftGen • But, we love Swift more! ❤

Slide 30

Slide 30 text

What we want? in code

Slide 31

Slide 31 text

What we want? in L10n

Slide 32

Slide 32 text

Scripting time! (Quickly)

Slide 33

Slide 33 text

Format key-function

Slide 34

Slide 34 text

Format the L10n extension

Slide 35

Slide 35 text

Update your build phase • Make your script macOS compliant • Add the new plurals phase

Slide 36

Slide 36 text

Build your project!

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Issue 2: ✅ Plurals with .stringdict files now correctly supported

Slide 39

Slide 39 text

Let's resume

Slide 40

Slide 40 text

Efficient Localization management ✓ Have single responsibility and substitution with a dedicated module ✓ Is Safe with L10n enum keys

Slide 41

Slide 41 text

Use Swift Scripts • Swift scripting is ✓ Easy and accessible for an iOS developer ✓ Powerful (shell calls, arguments, console printing, using Foundation (Codable, URLSession...) • Use your Swit scripts as: ✓ A custom command line tool ✓ As a custom build phase in your project

Slide 42

Slide 42 text

More ✓ Use Playgrounds to test & format it! ✓ Use aliases for your command lines, we are lazy

Slide 43

Slide 43 text

Retrieve this (detailed) talk on Medium • https://medium.com/back-market-engineering/swift- scripting-on-the-rescue-of-localizable-strings-files- management-on-ios-11d3e99af73

Slide 44

Slide 44 text

SwiftGen L10n+Plurals extension Thanks! Here the Gist files: Lokalise download & copy automation

Slide 45

Slide 45 text

We're hiring!