Localizing custom SiriKit intent
Asked Answered
F

5

24

My Xcode is v10 and I'm developing a custom intent for SiriKit, targeting iOS 12.

In Xcode 10, custom intents are designed in .intentdefinition files, where you can define your own parameters for intent phrases as well as the title of the intent and Siri shortcut for that intent. Building a project with a .intentdefinition file makes Xcode automatically generate an INIntent derived class for that intent.

My issue is that in order to support other languages than English so that the intent's title is show in the system's language in General > Siri & Search when the user is able to manipulate shortcuts for custom intents, I need to provide localized intent title for my .intentdefinition file.

When I try to add another language for my .intentdefinition file in the File Inspector and then build the project I get:

duplicate output file '/Users/.../IntentDefinitionGenerated/Intents/MyCustomIntent.swift' on task: IntentDefinitionCodegen /Users/.../ru.lproj/Intents.intentdefinition

This is likely happening because Xcode sees multiple .intentdefinition files in .lproj folders and tries to generate a same named class for each of them.

How do I localize my .intentdefinition file for iOS 12?

Farrah answered 18/9, 2018 at 10:39 Comment(2)
did u successfully registered custom vocabulary ?Launderette
@tobi Nope, same compiler errorsFarrah
H
33

Go to intentdefinition file -> File Inspector -> Select Localize -> Now select current language for your intentdefinition file. This will convert your existing intentdefinition file for current language.

Now again select the same intentdefinitionfile, add other language -> it will create a new Intents.strings file where you can customize the text for other locales.

Localized Intents.intentdefinition file

Intents.intentdefinition file after localization

Humanitarianism answered 24/9, 2018 at 13:11 Comment(7)
Does anybody know, if you followed the steps above and then at some later point in time add some strings to the intents definition file, how to get these added strings into the localization string files?Chavarria
Doesn't work. It produces a compiler error: Showing Recent Messages :-1: Multiple commands produce '.../SiriIntentsExtension.build/Objects-normal/arm64/NIIntentClassName.o': 1) Target 'SiriIntentsExtension' (project 'project') has compile command for Swift source files 2) Target 'SiriIntentsExtension' (project 'priject') has compile command for Swift source filesFarrah
@DesmondHume did you try cleaning your Build Folder ? Also check nevan's answer https://mcmap.net/q/547689/-localizing-custom-sirikit-intentHumanitarianism
Can we localise the category like: Order, View, Download etc?Randazzo
@Chavarria What I did was removed all the localizations (uncheck the checkboxes, removed files) and then add them again (by checking the checkboxes). If you're using git or some other source control, you should be able to see what changed.Thing
@asheeshVerma Yes we canHumanitarianism
The generated Intents.strings file will have a bunch of 6 character keys... Is there any way to make those human readable? If I add something new, I need to look at the .intentdefinition file's source code for the IDs?....Whereon
L
7

I had the same issue as @desmond-hume. In my case, I have an old xcode project that already contained some localizations before "Base" was available. The initial .intentdefinition file must be added as the Base localization. From there, further localization can be added and Xcode will add only a .strings file for each localization.

Without a base localization, Xcode adds a new .intentdefinition for each localization which causes the "multiple commands produce...." error.

You can add a Base localization under the main project settings via a checkbox. Some old projects (like mine) may also run into this issue: iOS - Using Base localization pane is always empty

Lineman answered 17/12, 2018 at 23:41 Comment(1)
You are a king among men! Thank you!Halie
S
3

It looks like you've already localized your Intent Definition file (since Xcode has put it into a ru.lproj folder) so the problem might be that you've two copies of the file in the "Compile Sources" build phase.

Go here:

Project -> App target -> Build Phases -> Compile Sources

and look for duplicate entries. If you find a duplicate, delete one of the copies

You can also try Editor > Validate Settings… to find duplicates

You can also try cleaning the build

Struck answered 27/9, 2018 at 9:39 Comment(0)
P
0

I've recently Localised the intents for my App, however after the original localisation, I added another Intent.

In Xcode 10.2.1 at least that I've checked, there is an "Export for Localization" option when you select the top level of your project. It will ask you to save the output. When you investigate your output, you should see an .xcloc folder for EACH of the languages you support. Dig down to the .xliff under "Localized Contents" and open it.

enter image description here

There you will find your treasure trove of the items and you're looking for and you're looking for items that don't have a 'target'

enter image description here

The engineers at Apple at dub dub showed me this, however I personally wasn't happy of this process, as you have to edit it, and then re-import it (assuming you send off your files to a translator and get an .xliff back.

The annoyance though with Intents is the fact that it uses arbitrary IDs and not something legible

I haven't found an easier way (yet) to locate the missing translations. Hope this helps!

Proa answered 7/10, 2019 at 20:16 Comment(1)
To locate the missing translations, instead of looking at the xliff file in a text editor, I suggest you use an app that can read the xcloc folder, parse the xliff file, and give you a summary of what translations are missing. One such app that allows you to analyse a whole folder of xcloc's at once (OrderBossLocalization in your screenshot above) is Loca Studio. Basic review and editing functions are free. (full disclosure: I am one of the developers of this app)Neo
M
0

you must be Project->info checked "Use Base Internationalization"

Next use the top answer method to create

Marylinmarylinda answered 18/9, 2022 at 21:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.