decybel07 / l10n-swift Goto Github PK
View Code? Open in Web Editor NEWLocalization of the application with ability to change language "on the fly" and support for plural form in any language.
License: MIT License
Localization of the application with ability to change language "on the fly" and support for plural form in any language.
License: MIT License
Swift PM fails to resolve the dependency to L10n-swift
It should install just like it does with other libraries. (example: Alamofire, PinLayout)
The dependency does not get resolved and swift package
aborts with an error.
Package.swift
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "Test",
products: [],
dependencies: [
.package(url: "https://github.com/Decybel07/L10n-swift.git", .upToNextMajor(from: "5.5.1")),
],
targets: [
.target(
name: "Test",
dependencies: [
"L10n-swift",
],
path: "Test"
),
]
)
$ swift package resolve
Updating https://github.com/Decybel07/L10n-swift.git
error: dependency graph is unresolvable; found these conflicting requirements:
Dependencies:
https://github.com/Decybel07/L10n-swift.git @ 5.5.1..<6.0.0
L10n-swift version: 5.5.1
Xcode version: Xcode 10.3, Build version 10G8
Swift version: Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Decybel07, thank you for sharing this awesome resource. Integration in Swift project is easy and well documented and it works perfectly well.
Only one issue remains from my perspective - either the Info.plist localication is not well documented or localization for Info.plist is not supported.
Would you pls comment on how to get this working?
Hi guys,
I would to use this lib but I had found there is not support for multiple arguments with plurals right?
For example, this is the value in Localizable.strings
:
"__id_runs" = "%d runs";
and and Localizable.stringsdict
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%1$#@lu_completed_runs@</string>
<key>lu_completed_runs</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>lu</string>
<key>zero</key>
<string>No runs completed yet</string>
<key>one</key>
<string>One %2$#@lu_total_runs@</string>
<key>other</key>
<string>%lu %2$#@lu_total_runs@</string>
</dict>
<key>lu_total_runs</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>lu</string>
<key>one</key>
<string>run completed</string>
<key>other</key>
<string>of %lu runs completed</string>
</dict>
</dict>
</plist>
This is the native call to use it:
let completedRuns = 1
let totalRuns = 2
let format = NSLocalizedString("__id_runs", comment: "")
let translatedString = String(format: format, completedRuns, totalRuns)
The result is correct: One of 2 runs completed
The same operation with L10n-swift ends with a wrong result because I can pass just one value as arg
parameter for plural()
function
let value = l10n.plural(for: "__id_runs", resource: nil, fittingWidth: nil, arg: 1, converting: { $0 })
which results in a wrong string: One %2$#@lu_total_runs@
Hi,
First of all, thanks for this library. Of all the projects I checked this one seems to handle plurals and localizations the best. I guess it takes handling plurals in Polish to understand this pain :P
I have some problems with String extension function. I try to call it as it is in examples:
"view_edit_profile_photos_content_text".l10n(args: 10)
For some reason XCode gives me following compile time exception:
Cannot invoke 'l10n' with an argument list of '(args: Int)'
Can you update the library to Swift 5.0?
Let me know if you need help i could create PR and do it myself :)
I'm working on custom framework. I have created an xcframework file , when I import this file into demo project then I got this error.
'L10n' is not a member type of class 'FrameworkMainClass.FrameworkMainClass'
With the string Phone\nNumber
in the .stringsdict
, I'm getting the following string "Phone\\nNumber"
instead of "Phone\nNumber"
.
"L10n {\n\tLanguage: en\n\tPreferred language: en\n\tSupported languages: [\"en\"]\n\tBundles: [\n\t\t\"/var/containers/Bundle/Application/1E0B4F9F-2F20-4503-8108-2C06E1FEDBE7/Cruise.app/en.lproj\",\n\t\t\"/var/containers/Bundle/Application/1E0B4F9F-2F20-4503-8108-2C06E1FEDBE7/Cruise.app/Base.lproj\"\n\t]\n}"
L10n-swift version:
5.7.3
Xcode version:
Xcode 12.4
Build version 12D4e
Swift version:
Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0
I use L10n-swift library for the project localization.
My project receives localisation files from the backend as json and stores it to the separate bundle in project's Documents folder.
And I have to load localizations from Documents to L10n.
I know that L10n can be created as a new instance and pass my bundle as parameter into init method, but IBInspectable extension won't work with the custom bundle, bcouz IBInspectable use shared singleton with default L10n initialization.
How can I load my Bundle to L10n.shared and use IBInspectable extension as Main bundle?
It works on Japanese and Italian perfectly (without needs to restart the app). But it did not works on Arabic and French even after restarting the app it not works. Kindly help me.
ios widget extension not working
widget language will change when app change language
when I use L10n.shared.language = "en" , app have changed.
widget still maintaining the original language when search L10n.shared.language.
**L10n-swift version: 5.10
Xcode version: Enter here xcodebuild -version
Swift version: Enter here swift -version
I have some static variables in a struct which are used to display error messages to users
struct AlertBody {
static let SOMETHING_WRONG = "There was an error service in your request. Please try again from while".l10n()
static let NO_NETWORK_ERROR = "No internet Connection found. Check your connection or try again.".l10n()
}
When I change the language, these static variables still give the message in previous language.
In order to get the messages in correct language I have to close and reopen the app.
But is there any other way to reload these static variables at the run time?
I get this build error (but only on one machine):
On a different machine, the identical code does not error and works just as expected.
The SupportConnectionError is defined thus:
I found that on the machine on which the error is occurring, the Pods/Manifest.lock has got a different version for L10n-swift (the one without the error has 5.7.3) :
Has there been a change between these two versions which would cause this error to occur?
I expect it to build as expected without the error. Honestly I'm a bit stuck - I'm not really an expert on Swift, but it baffles me why this error is appearing only on one machine. Any ideas that can help would be appreciated.
It is hard to say. Like I said it only seems to happen on one particular machine.
The environment should be basically the same. Both are using xCode 14.2, and the code is built from the same source.
Happy to do so if required? But since it is a build error, I don't know it would be relevant
L10n-swift version: 5.7.3 (works) 5.9.0 (errors)
Xcode version:
❯ xcodebuild -version
Xcode 14.2
Build version 14C1
Swift version:
❯ swift -version
swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
Target: x86_64-apple-macosx12.
I added a Localizable.strings with 3 languages into project and included it in build phase.
This is english version of it:
/*
strings.strings
NavigationDrawerController
Created by A.V.Ebrahimi on 4/21/17.
Copyright © 2017 CosmicMind. All rights reserved.
*/
"AppName" = "Mallowin";
But now this is not working :
toolbar.title="AppName".l10n()
Just installed this pod and tried plural localization via
"eventCount".l10n(arg: count)
Added this lines to Localizable.strings
"eventCount.one" = "%d event";
"eventCount.many" = "%d events";
"eventCount.other" = "%d events";
Traced code, self.bundle in this function is nil, so no resource is loaded
private func resource(named resourceName: String?) -> ResourceContainer {
let resourceName = (resourceName ?? "").isEmpty ? "Localizable" : resourceName!
return self.resources[resourceName] ?? {
let resource = ResourceContainer(bundle: self.bundle, name: resourceName)
self.resources[resourceName] = resource
return resource
}()
}
Version 5.1.0
System (default) menubar items don't update after a language change
Menubar adapts to new language selected
Menubar didn't adapt to new language
UI framework: SwiftUI
System: macOS Ventura 13.0
L10n {
Language: uk
Preferred language: en
Supported languages: ["en", "uk", "ru"]
Bundles: [
"/Users/egoryakovenko/Library/Developer/Xcode/DerivedData/Moc-cmqpfvhdudhbgibqasempmgnurue/Build/Products/Debug/Moc.app/Contents/Resources/uk.lproj",
"/Users/egoryakovenko/Library/Developer/Xcode/DerivedData/Moc-cmqpfvhdudhbgibqasempmgnurue/Build/Products/Debug/Moc.app/Contents/Resources/en.lproj"
]
}
(bundles change time to time, sometimes i have uk, sometimes i don't)
L10n-swift version: 5.10.2
Xcode version: Xcode 14.1 Build version 14B47 xcodebuild -version
Swift version: swift-driver version: 1.62.15 Apple Swift version 5.7.1 (swiftlang-5.7.1.135.2 clang-1400.0.29.51) Target: x86_64-apple-macosx13.0 swift -version
Hey
I found some interesting issue. Sometimes if key is too long and library don't find a proper translation in .plist app immediately shoots optional instead a key. Its generated by method "stringFromDictionary" in L10nResource. I suggest to use Swift version of Dictionary ;).
In the last version (4.1.1) of library option of localization in storyboard stopped working. Check this issue plz.
Is your feature request related to a problem? Please describe.
Nope
Describe the solution you'd like
Port for SwiftUI
Describe alternatives you've considered
N/A
Additional context
tried with this but doesnt work..
@State var currLang = L10n.shared.language
let langChanged = NotificationCenter.default
.publisher(for: .L10nLanguageChanged)
.makeConnectable()
.autoconnect()
VStack{}
.onReceive(langChanged) { _ in
self.currLang = L10n.shared.language
}
I have two Issues:
("Ok".l10n())
not changing in storyboard. - Language changes to default language every time I rerun appHere what I am doing for changing language:
L10n.shared.language = "fr"
After L10nLanguageChanged
notification fired I am relaunching storyboard
let delegate = (UIApplication.shared.delegate! as! AppDelegate)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
delegate.window!.rootViewController! = storyboard.instantiateInitialViewController()!
{
Language: fr
Preferred language: en
Supported languages: ["en", "fr", "pt-PT", "sw"]
Bundles: [
"/var/containers/Bundle/Application/E88839BF-E6FA-439F-A73A-F52B1A59DDBD/MyApp.app/fr.lproj",
"/var/containers/Bundle/Application/E88839BF-E6FA-439F-A73A-F52B1A59DDBD/MyApp.app/Base.lproj"
]
}
L10n-swift version: Swift 4.2
Xcode version: Xcode 10.2.1
Swift version: Swift 5
Note:
I have localized storyboard with other languages.
/* Class = "UILabel"; text = "Home"; ObjectID = "7D7-TL-I6S"; */
"7D7-TL-I6S.text" = "Accueil";
If I add text in L10n Text
in Attributes inspector
language changes works in storyboard.
Can I change language without assigning text (L10n Text
) to every control? I have localized every text in Main.strings(French) for storyboard.
I have looked into the example and try to put en.json in the project but it doesnt seem to work, please add some example in the readme or the example project
Thanks
Settings this would not reload all views, what should I do?
L10n.shared.language = "fa-IR"
Hi, I am using iOS 15. Tried both SPM and Pods. Firstly created "minutes_time.one" and "minutes_time.other" in Localizable.string in en.lproj. When I am trying to call "minutes_time".l10nPlural(1) there is an error No exact matches in call to instance method 'l10nPlural'. Then I've tried to do "minutes_time".l10nPlural(args: [1]), but then I've got "minutes_time.other" version instead of "minutes_time.one"
L10n {
Language: en
Preferred language: en
Supported languages: ["en"]
Bundles: [
"/var/containers/Bundle/Application/6353C86E-3F14-4D72-95DE-250F4628A4D1/.../en.lproj"
]
}
L10n-swift version: 5.10
Xcode version: 13.2.1 xcodebuild -version
Swift version: 5.5.2 swift -version
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.