1

My iOS application allows a user to begin by selecting a template document. For example, in Pages you could choose to start with the "Essay" template. That template document is copied and opened.

I'm running into a localization issue and cannot find out how to localize the displayed name of the resulting copied file. Again, an example with Pages. If my language is set to French and I select the "Reportage" (Essay) template, the name of the copied file is "Reportage".

My template files are located in my app's bundle resources. I'm using UIDocumentBrowserViewController and the following method to create the document

func documentBrowser(_ controller: UIDocumentBrowserViewController,
didRequestDocumentCreationWithHandler importHandler: 
@escaping (URL?, UIDocumentBrowserViewController.ImportMode) -> Void)

The importHandler is eventually called with .copy like so:

importHandler(url, .copy)

My template files are quite large and it does not make sense to ship duplicates with localized names. We have a workaround where we first create a copy with the properly localized file name. We then use that resulting file's URL in importHandler(url, .copy), but having to duplicate the file twice seems wasteful.

I've seen reference to localizedNameKey in the documentation, but there's very little information about how to set that value. Assuming it's relevant, how do I make use of the localizedNameKey? Is there some plist where this per file localization info is specified?

Serban
  • 11
  • 2

1 Answers1

0

If you create a copy first, you can use the .move mode instead of .copy in order not to copy twice. Note that a copy should be quite cheap if you use the right API as it should be an APFS copy-on-write clone.

Thomas Deniau
  • 2,488
  • 1
  • 15
  • 15