SwiftUI AppIntents iOS16: How to localize Summary? - swift

Im trying to localize the Summary of my new SwiftUI AppIntent on my Swift project for making new Shortcuts.
I am not able to localize the Summary.
I have created a AppShortcuts.strings with Localize of English and Spanish languages like in this page appears: click here.
AppShortcuts.string (es):
"add ${numberOne} ${numberTwo}" = "Sumar: ${numberOne} ${numberTwo}";
Shortcut:
static var parameterSummary: some ParameterSummary {
Summary("add \(\.$numberOne) \(\.$numberTwo)") {
\.$numberThree
\.$numberFour
}
}

As stated in the article you have already mentioned these directives have to go into Localizable.strings:
ParameterSummary –
This one is tricky. You'd think that because it has a variable it should be with the translations of the phrases in AppShortcuts.strings, but no, it belongs in Localizable.strings.
Don't know why but that works for me.

Related

Does apps automatically get translated? If not, how do I approach this problem?

Say I have an app that has one label that says "hello". I publish it "worldwide" on the app store.
If someone purchases it in China, and opens it, does the app store auto translate it to "Ni hao".
If not, how do I combat this issue? Do I have to make an app for each country? Is there a way to auto translate in Xcode/coding?
Application do not translate automatically.
You need to use localization.
You set up Localizable.strings (China) and one for English version
English file:
"hello" = "hello"
China file:
"hello" = "Ni hao"
Inside your application you need to use NSLocalizedString
static let hello = NSLocalizedString("hello", comment: "Tab Bar title, and navigation bar title for Profile")
label.test = hello
Now will translate depends of device language setup
more examples https://www.raywenderlich.com/250-internationalizing-your-ios-app-getting-started

Linking pages in Swift Playgrounds [Xcode]

I am new to swift playgrounds and ran into some problems while making a swift playground in Xcode.
This is my main Playground page
import UIKit
import PlaygroundSupport
import SpriteKit
let secondScene = Index()
let master = FirstScene()
let root = UINavigationController(rootViewController: master)
PlaygroundPage.current.liveView = root
But when I tried adding Next Topic in both the source class in Swift and the playground page itself the link does not appear.
NOTE: I am using Swift Playgrounds in Xcode not a Playgroundbook on an iPad.
Also, inside sources folder of my main page I declared all classes as public, is that the right way to use the helper swift files in source?
I tried creating a new playground and added pages which have default links but still no output.
Looking at your screenshot, you've got the code right. The syntax to link to the next page is [Next Page!](#next). All you need to do now is:
- In the Xcode menu bar, click Editor
- Click 'Show Rendered Markup'
That's it. You can place markup wherever you like. Remember to replace spaces with %20 when linking to a playground page, e.g. [My Page #2](My%20Other%20Page)
You would benefit from reading Apple's Markup Formatting Reference.
To create a link to another page you will do the same thing that I did above to create a link to that reference in Markdown:
[Next Topic](Pretend%20Topic%20Name)
You can actually do something like this as well:
[Next Topic](#next)

Xcode 8.2.1 not showing documentation description on autocomplete

I'm having problems adding documentation to my code in Xcode 8.2.1.
Here's my code:
/// Test documentation method
///
/// - Parameter string: The input string
/// - Returns: The output bool
func testMethod(string:String) -> Bool {
if string == "YES" {
return true
}
return false
}
The documentation shows as expected in the quick help window but the description doesn't show in the code autocomplete window.
Is there a way to get the description to show in the autocomplete box as in the image below:
You are right, the descriptions you added to the top of your methods and properties don't appear in the popover anymore.
As noted, you can only see the descriptions of Apple's own methods and properties.
The reason being that Xcode doesn't parse these from their classes but rather from a separate documentation set (which you can find in Xcode's Help/Documentation and API reference tab).
So unless Apple decides to change this, I'm afraid it won't be possible to see your own in the popover.
You could keep an eye on existing doc set generators (AppleDoc, Jazzy), maybe they'll offer a way to link their documentation to Xcode's popover.
Keep in mind that you do see your own comments when opening the quick help popover with alt + click on a method or property.
For me the best way to resolve this is by cleaning the project Shift+Command+K, and if that is not working, it is a god idea to remove Derived Data folder.
To remove this folder go to Xcode preferences, Locations tab
and click on the small arrow to open a finder, and remove manually the folder.
Restart Xcode, and check if now is working
https://developer.apple.com/library/content/documentation/Xcode/Reference/xcode_markup_formatting_ref/MarkupFunctionality.html#//apple_ref/doc/uid/TP40016497-CH54-SW1
please refer the official documentation

Steps for internationalisation in Xcode

I've been trying to add a Portuguese translation to my app. At the moment it's all in English. (well, it started that way).
I'm using a Storyboard for the main part of the UI. There are also a couple of additional xib files for reusable UI in table etc...
Anyway, I set out on the path of trying to internationalise the app and managed to convert the Storyboard to Portuguese.
I then tried to set up some strings (just a couple to begin with) to make translations of those also.
I've now got an storyboard that's only in Portuguese (I lost the English version) and none of the strings are being translated properly anyway.
I've set all the string back to just use #"blah" now (I'd put NSLocalizedString in a couple of places).
So I should be back to square one (once I fix the storyboard).
Anyway, is there a list of steps somewhere of how to go about making an app localised?
Any help appreciated.
There are couple of tutorials available - this is one of the good ones: http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial
This will definitely help you to get started real quick!
However, if you are on iOS6 xCode 4.5 you should also check the new features regarding localization. Apple now has also gon the route to have just one XIB (not like before multiple XIBs, one per language - which was impossible to maintain)
Probably the most important point is to always use NSLocalizedString, so there is no need for multiple XIBs. And then it's real easy to just add a new strings file for each language.
All you have to do then is in the Project Editor select your project -> select the Info tab on the right -> scroll all the way down -> there you find the localizations, press the little + on the buttom to add a new language. That's it.

Change language in app - how to restart?

I want to give the user the possibility to change the language in my app.
The way to do this is described here, in monotouch code to set the preferred language to Dutch and alternate language to English:
NSUserDefaults.StandardUserDefaults.SetValueForKey
(NSArray.FromStrings("nl", "en"), new NSString("AppleLanguages"));
You have to restart the application before this will take effect. But on the iPhone 4 the app does not restart when you close it, it is just hidden. Is there a way to force an app to restart after closing?
Thanks Dimitris. So changing the language at runtime is not that simple.
I found a solution which works in my case:
When the user changes the language I use the solution described by Mauro Delrio in "How to force NSLocalizedString to use a specific language". In monotouch:
string newLanguage = "nl";
myBundle = NSBundle.FromPath(NSBundle.MainBundle.PathForResource(newLanguage, "lproj"));
All strings will now be loaded in the selected language with myBundle.LocalizedString(...). Of course, everything which was already printed on a view is not yet translated. But I found an easy way to reset all views. In my app I use a MainTabController which looks like this:
public class MainTabBarController : UITabBarController
{
public override void ViewDidLoad()
{
Reset();
SelectedIndex = 2;
}
public void Reset()
{
ViewControllers = new UIViewController[]
{
new ViewControllerTab1(),
new ViewControllerTab2(),
new ViewControllerTab3(),
new ViewControllerTab4(),
new ViewControllerTab5()
};
}
}
So all I have to do is call Reset like:
((AppDelegate)UIApplication.SharedApplication.Delegate).MainTabBarController.Reset();
All current views are disposed and re-created in the correct language. Seems like a trick, but it is perfectly legal and documented, see Apple documentation for MainTabBarController viewControllers property. It even activates the same tab index as the one which was active, so for the user it seems that nothing but the language is changed.
Of course, any unsaved data in all views is lost, so if this is a problem, you have to find a way to save this before resetting.
No there is no way to restart an app. You can only force it to terminate when the users presses the home button by setting the property "UIApplicationExitsOnSuspend" in your Info.plist file to true.
The trick to use specific language by selecting it from the app is to force the NSLocalizedString to use specific bundle depending on the selected language ,
here is the post i have written for this http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html
and here is the code of one sample app https://github.com/object2dot0/Advance-Localization-in-ios-apps
As an additional note, to force the UIBarButtonSystemItem to change their locale, you have to add
<key>CFBundleDevelopmentRegion</key>
<string>nl</string>
to your info.plist. Just fire up TextEdit and place it somewhere. Hope this helps!