I localised almost all labels and buttons. However, when I localise my timerLabel, the words "min" and "sec" are not translated in other language. Here's the timer function.
enter image description here
In order to localise countDownLabel, I used this localisation method below.
func setUpTranslation() {
countDownLabel.text = NSLocalizedString("CountDown", comment: "")
}
I tried to set "CountDown" key for the countDownLabel in Localizable.strings(Spanish) like these below one by one. But they didn't work.
"CountDown" = "(%d)min(%d)seg"
"CountDown" = "(minutes)min(seconds)seg"
"CountDown" = "%dmin%dseg"
"CountDown" = "\(%d)min\(%d)seg"
Would you tell me whether there is any other sign that I need to add to successfully translate those words or not?
Related
I am working on my SwiftUI project and added some AppIntents for the Shortcuts app. Currently I am not able to localize the title and description. The title and the description are of type LocalizedStringResource (available from iOS16+).
I tried to localize the following code to German, but I don't know how to do it.
struct Add_Memory_Shortcut: AppIntent {
// The name of the action in Shortcuts
// TODO: Localization
static var title : LocalizedStringResource = "Create Memory"
// Description of the action in Shortcuts
// Category name allows you to group actions - shown when tapping on an app in the Shortcuts library
static var description: IntentDescription = IntentDescription("Create a new memory", categoryName: "Creating")
}
Any help or link is appreciated. Thanks :)
I tried everything, only one thing works, add your localization strings in
Localizable.strings
And if you want to localize string with paramter
//Localizable.strings
"hello_user%#" = "Hello %#";
//Your AppIntents
let welcomeMSG = LocalizedStringResource("hello_user\(userName)")
LocalizedStringResource doesn't have a ton of documentation available, but take a look at https://developer.apple.com/documentation/foundation/localizedstringresource/3988421-init:
init(
_ keyAndValue: String.LocalizationValue,
table: String? = nil,
locale: Locale = .current,
bundle: LocalizedStringResource.BundleDescription = .main,
comment: StaticString? = nil
)
For table, it says: "The name of the table containing the key-value pairs. If not provided, nil, or an empty string, this value defaults to Localizable.strings." In my experience that's not currently true, and you may need to explicitly point it to your translations, e.g.:
let myString = LocalizedStringResource("Hello, big world!", table: "Localizable.strings")
If you do that, supply appropriate translations, and set a locale that matches, you will see the localized version presented -- at least within a SwiftUI view:
Text(myString)
the problem is that the text has value which declares the day before the text
so idk how to translate this text that includes value.
untilEventDay =
'${pDate.difference(DateTime.now()).inDays},days/ until event day'
.tr;
in translation page :
,days/ until next event day': 'ڕؤژ ماوه/ تاوهكو ئیڤێنتی داهاتوو',
you should separate the value's string from your translation
var eventDayCountDownTitle = '${pDate.difference(DateTime.now()).inDays}' + ',' + days/ until event day'.tr;
and if you need your day number to be in a specific language, you can use a map or a helper method. map solution would be something like this:
Map<String,String> englishToPersianNumber = {'1' : '۱'}
and then use it in your string :
englishToPersianNumber[pDate.difference(DateTime.now()).inDays.toString()]
Important: to have a cleaner code, you can create a helper method to generate your desired string, and call it in your text widget. the code would be more understandable that way. Also, you can add handle any conditions that may later be added to the string generator. like if it's the last day, write something else instead of 0 days remaining.
String eventDayCountDownTitle(int remainingDays) {
if(remainingDays == 0) return "Less than One day to the event".tr;
return '${remainingDays.toString}' + ',' + 'days/ until event day'.tr;
}
ps. your question's title is wrong, you should change it to what you're explaining in the caption
First, I'm very new to Swift, and coding in general. I'm trying to use the correct terminology, so I apologize if it makes no sense. Doing my best!
Ok, so there appears to be a lot of information/answers on ways to random select strings (or integers, etc) from an array without repetition. However, in my current application, I am not using an array (I kind of am but not directly related to the question). But rather a #State designation, in which the variable has an initial value (a string with a number and letter) and is later updated when a button is pushed. The string changes to a randomly selected string from my assets folder based on the file name, which will be the same word but with a different number and letter. What is the simplest way to keep from updating to strings that have already appeared?
Example of what the code looks like:
#State var relevantWord = "bird"
Button {
let randoNum = Int.random(in: 1...5)
let x = ["a", "b", "c", "d"]
let randoLet = x.randomElement()
relevantWord = "bird" + String(randoNum) + String(randoLet)
}
So, the relevantWord variable starts as "bird2c" for example, and each time the button is pushed, it will change to "bird3b" then "bird4a" etc. I just want to keep it from repeating and return nothing when the assets are depleted. Thanks!
I'm trying to send a mail via the powermail extension to different receivers, depending on the value a user has selected in a form dropdown. This practice of dynamic receivers is described in the powermail documentation. Basically:
receivers1.email = CASE
receivers1.email {
key.data = GP:tx_powermail_pi1|field|receiver
1 = TEXT
1.value = receivera#domain.org
default = TEXT
default.value = receiverb#domain.org
}
Now I'm facing the following problem: my values for "receiver" are not numeric (as in the example), but text values from a dropdown. Some of them contain spaces, some of them contain umlauts (öäüß). If I try to add …
Not wörking = TEXT
Not wörking.value = anotheremail#nowhere.org
Typo3 will complain and not update anything. (Bad property!
You must enter a property with characters a-z, A-Z and 0-9, no spaces!Nothing was updated!)
I tried simply 'escaping' the forbidden characters with a backslash, not working. Had an idea of converting the key.data via stdWrap rawUrlEncode, but did not work either. Google came up with this solution, but I don't understand what's going on and could not use it successfully.
How can I get around this? Thanks a lot for any kind of hint!
I pretty like your rawUrlEncode solution. Can you provide us your solution of it here? According to this online converter the result should be something like:
key.data = GP:tx_powermail_pi1|field|receiver
key.stdWrap.rawUrlEncode = 1
Not%20w%C3%B6rking = TEXT
Not%20w%C3%B6rking.value = anotheremail#nowhere.org
Maybe for each CASE some signs like "%" are not allowed. In that case you maybe refer to the "replacement" function. https://docs.typo3.org/typo3cms/TyposcriptReference/8.7/Functions/Replacement/Index.html#replacement
key.data = GP:tx_powermail_pi1|field|receiver
key.stdWrap.replacement {
10 {
search.char = 32
replace = _
}
// Add umlauts and other signs!
}
Not_wörking = TEXT
Not_wörking.value = anotheremail#nowhere.org
I'm building up a set of Complications and have come to the CLKComplicationTemplateUtilitarianLargeFlat which only has one textProvider.
I want to display some text, along with a relative date. So I tried doing this:
let date = CLKRelativeDateTextProvider(date: NSDate(), style: style, units: units)
let template = CLKComplicationTemplateUtilitarianLargeFlat()
template.textProvider = CLKSimpleTextProvider(text: "next: \(date)")
But all I get is:
<CLKRelativeDateTextProvider: 0x79860b80>
Can you extract the raw text from the CLKRelativeDateTextProvider or combine it with a CLKSimpleTextProvider in some way?
Pass in the CLKRelativeDateTextProvider object to the format string, as mentioned in Apple's code:
#interface CLKTextProvider : NSObject <NSCopying>
// By passing one or more CLKTextProviders in the format substitutions, you can add text around the output of a text provider.
+ (CLKTextProvider *)textProviderWithFormat:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2);
#property (nonatomic) UIColor *tintColor;
#end
Here is an example:
id relativeDate = [CLKRelativeDateTextProvider textProviderWithDate:[NSDate dateWithTimeIntervalSinceNow:12 * 60]
style:CLKRelativeDateStyleNatural
units:NSCalendarUnitMinute];
template.textProvider = [CLKTextProvider textProviderWithFormat:#"next: %#", relativeDate];
The time shown in the date provider will still update as time passes without having to refresh anything.
With the current version of ClockKit you can not pull any String data from a text provider nor combine 2 or more text providers. The only text providers available to you are:
CLKDateTextProvider
CLKRelativeDateTextProvider
CLKSimpleTextProvider
CLKTimeIntervalTextProvider
CLKTimeTextProvider
To answer your question you will not be able to display the word "Next" and then a date in your complication. Due to the way ClockKit is designed and the way your complication data should be designed, however, you shouldn't be needing to display "Next" at all. Your complication should be automatically showing the next item from your data relative to the current time.