Decybel07 / L10n-swift

Localization of the application with ability to change language "on the fly" and support for plural form in any language.
MIT License
315 stars 32 forks source link

Plural localization not working #12

Closed entropious closed 6 years ago

entropious commented 6 years ago

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

Decybel07 commented 6 years ago

Could you answer the following questions?

entropious commented 6 years ago

It's in base.lproj folder and every other string in this file works fine

Decybel07 commented 6 years ago

Can you paste what returns the following code?

debugPrint(L10n.shared)
entropious commented 6 years ago

Right now i can't test it, will answer tomorrow

entropious commented 6 years ago
L10n {
    Language: en
    Preferred language: en
    Supported languages: ["Base", "ru", "en"]
    Bundle: nil
}
entropious commented 6 years ago

In private func languageChanged(oldValue: String? = nil) you only looking for en.lproj, ignoring Base.lproj where actual localization is located

Decybel07 commented 6 years ago

Yes you are right. As the language is set, files from this language are taken, while others are ignored.

A proposal to solve your problem:

  1. Move all files from base.lproj to en.lproj
  2. Remove Base from the list of supported languages
entropious commented 6 years ago

Base localization is used for all languages not currently supported. If i set french language, base localization will be used. This is iOS default behaviour. So fallback to base localization if localization for current language is not found seems pretty reasonable to me.

Decybel07 commented 6 years ago

For me, this is not a bug, this is intentional behavior. If the application supports French and user set French, then why should it display text in English?

entropious commented 6 years ago

If app supports french, than it would be found by language in fr.lproj. I'm talking about behaviour when {language}.lproj is not found.

Decybel07 commented 6 years ago

If {language}.lproj is not found then:

Tsarfolk commented 6 years ago

@Decybel07 from Apple documentation For example, if you select English as the development language, Xcode inserts the resource file in the Base.lproj project folder but not the en.lproj folder because the resource is already in English.. At the end of the page https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/InternationalizingYourUserInterface/InternationalizingYourUserInterface.html

Decybel07 commented 6 years ago

You convinced me, I'm going to add support for "base internacionalization"

Decybel07 commented 6 years ago

@entropious, @Tsarfolk Problem is solved, the base internationalization is added to the library.