Git Product home page Git Product logo

localize's People

Contributors

adbqpa avatar andresilvagomez avatar dclelland avatar gustavoggs avatar imryan avatar kazaimazai avatar linusgeffarth avatar pipemontoya avatar siberianbearr avatar simone-gasparini avatar tladesignz avatar unchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

localize's Issues

Static UITableView rows not localized properly

Issue

I have a static table that loads localized properly.
Once the language change, the rows' text change to the default (used in the cell xib)

Correct
Schermata 2020-05-13 alle 23 11 39

Wrong
Schermata 2020-05-13 alle 23 11 52

Localize Environment

  • Localize version: 2.3
  • Xcode version: 11.4.1
  • Swift version: 5
  • Platform(s) running Localize: iOs 13.4.1
  • macOS version running Xcode: Catalina 10.15.4

Localize Config

My localized JSON files are in a sub-folder
Schermata 2020-05-13 alle 23 17 23

// Localize
let localize = Localize.shared
localize.update(provider: .json) // Set your localize provider.
localize.update(fileName: "lang") // Set your file name
// Set language based on system
let locale = Locale.preferredLanguages.first?.components(separatedBy: "-").first?.lowercased() ?? "en"
localize.update(language: locale)

What did you do?

Here the code I'm using for creating the table

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "configCellIdentifier", for: indexPath) as! CellWithIconTableViewCell
        cell.accessoryType = .disclosureIndicator
        
        // THIS IS THE JSON FILE
        //"account": {
        //    "update-language": "Choose the new language",
        //    "static-table": {
        //        "ranking": "Check your rank",
        //        "account": "Account",
        //        "support": "Support",
        //        "about": "About",
        //        "language": "App language"
        //    }
        //},
        
        switch indexPath.section {
        case 0:
            switch indexPath.row {
            case 0:
                cell.setProperties(icon: UIImage(named: "glyphicons-basic-393-medal"), text: "account.static-table.ranking".localized)
                return cell
            case 1:
                cell.setProperties(icon: UIImage(named: "glyphicons-basic-4-user"), text: "account.static-table.account".localized)
                return cell                
            default:
                break
            }
        case 1:
            switch indexPath.row {
            case 0:
                cell.setProperties(icon: UIImage(named: "glyphicons-basic-587-bug"), text: "account.static-table.support".localized)
                return cell
            case 1:
                cell.setProperties(icon: UIImage(named: "glyphicons-basic-196-circle-empty-info"), text: "account.static-table.about".localized)
                return cell
            case 2:
                cell.setProperties(icon: UIImage(named: "glyphicons-basic-419-worl-east"), text: "account.static-table.language".localized)
                cell.accessoryType = .none
                return cell
            default:
                break
            }
        default:
            break
        }
        
        return UITableViewCell()

    }

This is the code used for changing the language

private func chooseLanguage() {
        let actionSheet = UIAlertController(
            title: nil,
            message: "account.update-language".localize(),
            preferredStyle: UIAlertController.Style.actionSheet
        )
        
        for language in Localize.availableLanguages {
            let displayName = Localize.displayNameForLanguage(language)
            let languageAction = UIAlertAction(
                title: displayName,
                style: .default,
                handler: { (_: UIAlertAction!) -> Void in
                    Localize.update(language: language)
            })
            actionSheet.addAction(languageAction)
        }
        let cancelAction = UIAlertAction(
            title: "general.alerts.cancel".localize(),
            style: UIAlertAction.Style.cancel,
            handler: nil
        )
        
        actionSheet.addAction(cancelAction)
        self.present(actionSheet, animated: true, completion: nil)
    }

What did you expect to happen?

I expect to see the right localization

What happened instead?

The rows present the default text

Localize with parameter not work

Hi!
I am trying to localize a key like this:
"This_is_key" = "You have % apples";
But it always fallback to base language. (in my case, I localize for Vietnamese). But the key without parameters still working in Vietnamese.

I tried so many ways but it still not working.

Please check

Keep the string that had localize key

Base on your example, what if I want to keep the string "app.label" without remove its key. For example, I want to localize "app.label" in the first viewcontroller but I don't want to localize "app.label" in the second viewcontroller. Any solutions ?

Swift tool version error

Issue

Hello, I have added this library by SPM and I have an error:
Error

Localize Environment

  • Localize version: I fetched master
  • Xcode version: 14.0.1
  • Swift version: 5

Localize Config

default

Btw. Will you make new release? If I want to have latest code I need to get master branch, not version.

Support for simplified and traditional Chinese

Issue

The library does not handle properly languages that are coded by iOS in three components. I have tried to include translation for both simplified and traditional Chinese. The language variable is set as follow:

  • zh-Hans-US for simplified Chinese
  • zh-Hant-US for the traditional Chinese

However, I cannot create json resource with the name zh-Hans-US / zh-Hant-US as last component encode the regional settings. In my case it is US. I have tried to name files: lang-zh-Hant.json and lang-zh-Hans.json but it results in selecting default language as the library always fall back to the single component file name (lang-zh.json) which also cannot be found.

Localize Environment

  • Localize version:
  • Xcode version:
  • Swift version:
  • Platform(s) running Localize:
  • macOS version running Xcode:

Localize Config

/// Please put here your config

What did you do?

ℹ Please replace this with what you did.

What did you expect to happen?

ℹ Please replace this with what you expected to happen.

What happened instead?

ℹ Please replace this with of what happened instead.

Add support for external datasource

First of all let me thank you for the awesome library. It just saved me lots of code and helped keep things neat.

One feature I think would add value is option to add an external datasource other than App's Bundle. So, we could read from JSON files that is in application's documents directory. This helps to make the localisation files dynamic.

A simple use case would be the ability to push any changes to the strings to the app from server. The app could just replace contents in the documents directory. I am assuming we cannot alter contents in the Bundle. Correct me if I am wrong.

Feature Request: create variables from .json / .strings

A new feature I'd love to have in this library (which would take huge efforts, I believe, though) would be to integrate the feature that Laurine has.

Ported over, it would look something like this:

lang-en.json

{
    "login": {
        "welcome": "Hey %, what's up?"
        "username": "Username",
        "password": "Password"
    }
}

ViewController.swift

welcomeLabel.text  = Localize.login.welcome(value: "Andres") // Hey Andres, what's up?
usernameLabel.text = Localize.login.username

That'd be super awesome!

Localize UIElements

How would I go about localizing the following UIElements...

  • UISegmentedControl's titles
  • UITextField's placeholders?

...all in storyboard?

Podspec file does not validate when added resource_bundle for localization in 'BinaryFramework'

Issue

ℹ Please provide a quick description for this issue.

Xcode - 11.5
MacOS - 10.15.3
Swift - 5

Localize Config

Pod::Spec.new do |s|

s.platform = :ios
s.ios.deployment_target = '11.1'
s.name = "*"
s.summary = "
for customer."
s.requires_arc = true

s.version = "0.1.2"

s.license = { :type => "MIT", :file => "LICENSE" }

s.author = { "Swapnil G" => "**" }

s.homepage = "***"

s.source = { :git => "***",
:tag => "#{s.version}" }

s.ios.framework = "UIKit"
s.framework = "WebKit"
s.ios.framework = "HealthKit"

s.dependency 'SQLite.swift','> 0.12.2'
s.dependency 'Alamofire', '
> 4.9.1'
s.dependency 'Charts', '> 3.4.0'
s.dependency 'CryptoSwift', '
> 1.3.0'
s.dependency 'NVActivityIndicatorView', '> 4.8.0'
s.dependency 'SwiftSoup', '
> 2.3.0'
s.dependency 'SwiftyJSON', '> 5.0.0'
s.dependency 'DropDown', '
> 2.3.13'
s.dependency 'HGCircularSlider', '> 2.2.0'
s.dependency 'RealmSwift', '
> 4.3.2'

s.dependency 'HGCircularSlider', '> 2.2.0'
s.dependency 'DropDown', '
> 2.3.13'

s.source_files = ".framework/Headers/*.h"
s.public_header_files = "
.framework/Headers/*.h"
s.vendored_frameworks = "**.framework"

s.resource_bundle = { "**" => ["Localize/.lproj/.strings"] }

s.swift_version = "5.0"

end

What did you do?

Added strings file for hindi and english language checked with normal framework (not binary framework), it works as expected but not with the binaryframework

What did you expect to happen?

Localization should work for binaryframework also.

What happened instead?

Validation failed with error - [iOS] file patterns: The resource_bundles pattern for Framework_Bundle did not match any file.

How to use in Objective-C ?

My project is mixing between swift and objective-c.
I can't find the instruction to use with objective-c view controller.

Display Languages in their original languages.

Greetings, dear Localize developer!
Your work is immaculate and useful beyond belief. Your guides are simple and easy to follow and It helped me save tons of time. The only thing I was wondering about is why not display languages in their original, i.e. action sheet now displays list of languages in the language currently chosen.

  • English
  • French
  • Cancel
    What could be even better is to give an option (or set as default) to show them like this:
  • English
  • Francais
  • Cancel

How it looks now:
screen shot 2018-05-25 at 11 12 45 am 2

How IMHO would be better:
screen shot 2018-05-25 at 11 12 45 am 2 copy 2

PS. For some reason, O'zbek is written as O'Zbek (capital Z), could you please fix that too. I'd do it myself, I just don't know how.

How to handle Localizable.strings file

Hi,
This is not an issue according to this pod. I already used this pod in another iOS application. It is nice and very easy to understand and easy to implement.
I have a situation here. I am working a project which already contains localization file for the two languages. The code is written is like this for the text.
NSLocalizedString("Use_Thumb", comment: "")

Is there any possibility to use this pod to handle the Localizable.strings file. If possible. How to use it.

The project is updated to swift 4.2 version.

please give suggestions.

screen shot 2019-02-23 at 12 37 24 pm

Determine whether a localization exists for a key

For error messages, I try to generically access the localized strings.

Example json:

"errors": {
    "some_error": "Something went wrong!",
    "some_other_error": "We're not sure what's happening..."
}

From the API, I receive an error code and would like to do:

let errorCode = ... // from API response
let errorMessage = "errors.\(errorCode)".localized

Now, in case I forgot to add localization for an error code, or the backend added a new error code, before I was able to update the app, I'd like to do a fallback, when there's no localized string for this key.
Currently, I compare the returned string to the key:

let key = "errors.\(errorCode)"
if key.localized != key {
    errorMessage = "There's an unknown error."
}

However, I'd much rather do something like this:

let key = "errors.\(errorCode)"
if Localize.shared.localizationExists(forKey: key) {

See a possible implementation for this below:

/// Determines whether a localized string exists for given key
///
/// - parameter key: localization key
/// - returns: boolean value determining whether a localized string exists for give key
public func localizationExists(forKey key: String) -> Bool {
    return key.localized != key
}

System button with default title/change in runtime not localized correctly

Issue

System button with default title/change in runtime not localized correctly

Localize Environment

  • Localize version: (2.1.0)
  • Xcode version: 10.1 (10B61)
  • Swift version: 4.0
  • Platform(s) running Localize: iOS
  • macOS version running Xcode: 10.14.2 (18C54)

Localize Config

Localize.update(fileName: "Localization")
Localize.update(defaultLanguage: "en-US")
Localize.update(language: "en-VN")

What did you do?

I had a button (from storyboard) with default title is "Start Reading". In the runtime, that button can be change to "Resume chap.1" for example. It work perfect until I hit that button, the title fade to "Start Reading" instead of "Resume chap.1". The title only change when click and hold the finger on it, after releasing, it fade back to correct title "Resume..." The button I use is system type

Button type: Default system type
Default title: "Start Reading"
Runtime title: "Resume chap.1"
Click & hold button: Fade to "Start Reading"
Release button: Fade to "Resume chap.1"

Not add English option

Issue

ℹ Please provide a quick description for this issue.

Localize Environment

  • Localize version:
    4.1.0
  • Xcode version:
    10.1
  • Swift version:
    4.2
  • Platform(s) running Localize:
    iphone
  • macOS version running Xcode:

Localize Config

/// Please put here your config
lang-en, lang-fr, lang-sv
It shows only fr and sv 2 options, not showing en options.

What did you do?

ℹ It does not add english option
.for language in Localize.availableLanguages {
let displayName = Localize.displayNameForLanguage(language)
let languageAction = UIAlertAction(
title: displayName,
style: .default,
handler: { (_: UIAlertAction!) -> Void in

                Localize.update(language: language)
        })
        actionSheet.addAction(languageAction)
    }

Cannot display the correct localization

Hi, I have a problem using this localization framework.

Here is the step I have done

  1. install localize using cocoapods
  2. import Localize in AppDelegate.swift and put below code inside "application" function
    let localize = Localize.shared
    localize.update(provider: .json)
    localize.update(fileName: "lang")
    localize.update(defaultLanguage: "en")
    print(localize.language())
    print(localize.availableLanguages())
  3. then, I created "lang-en.json" and put it inside my working folder
  4. I add print("hello.world".localize()) somewhere in the viewController
  5. I tried to run the program
  6. the result which is shown in the console is
    en
    []
    hello.world

Am I missing something? or they cannot find my "lang-en.json" file?

Thank you

Updating the language for a tableview with separate tableviewcell files

Hi, thanks for your work.

I am trying to translate an app that is built with a tableviewcontroller and each row has a separate tableviewcell file, and each tableviewcell has a collectionviewcell. This is to present a view like NetFlix or the AppStore: collectionviews embedded in tableviews.

The problem with the translation comes when I want to translate in the HomeTableViewController file. Because the strings to translate are in the TableViewCell file, that has no viewdidload or viewwillappear.

Any help would be very much appreciated.

Fallback language

Is there a way to set the fallback languages if I want something different from what apple does?

Not localizing automatically

First off, thanks for this awesome library. I love how simple, yet flexible, it is!
Keep up the good work!


I've setup localization for English and German: lang-en.json, lang-de.json.
It works perfectly when manually setting the language in code by doing localize.update(language: "de").
However, it does not automatically set the language when changing my device's language.

Am I missing something?


Update:

I figured I could manually set the language to the device's language by passing...

Locale.preferredLanguages.first?.components(separatedBy: "-").first.lowercased ?? "en"

...as language code.
Is this the way it's supposed to be?

Double request in one string - array

Issue

Doesn't grab both strings when put into one.

Localize Environment

  • **Localize version:Newest
  • **Xcode version:10.2.1
  • **Swift version:5
  • Platform(s) running Localize:
  • **macOS version running Xcode:10.14.2

What did you do?

"kingsen.game.mode.hearts".localize() + " kingsen.game.mode.jack".localize(), in an array

What did you expect to happen?

  • Hearts Jack
    To grab and show both of the strings

What happened instead?

  • Hearts kingsen.game.mode.jack
    It only grabs the first one. The second one is just displayed as kingsen.game.mode.jack instead of the string.

UITabbar text not updated until app restart

Issue

ℹ Please provide a quick description for this issue.
Tabbar string not refreshed until app restart

Localize Environment

  • Localize version: 2.3.0
  • Xcode version: 12.5

Localize Config

/// Please put here your config
UITabBarItem(title: "More_title".localize(), image: UIImage(named: "icon-more-menu"), tag: 4)

What did you do?

ℹ I try to change the language from setting page.

What did you expect to happen?

ℹ The tabbar text should change to respective language immediately.

What happened instead?

ℹ It didnot changed to latest updated language.

Crash on iOS8

On iOS 8 app crashes when You change the language after some ViewControllers was destroyed.

It crashes on line:
NotificationCenter.default.post(name: Notification.Name(rawValue: LocalizeChangeNotification), object: nil)
In method:
public func update(language:Languages) -> Void
Of class:
LocalizeCommonProtocol

It most likely because of not removing the observer from NotificationCenter that are added in awakeFromNib methods in extensions of UIControlls in file LocalizeExtensions.

This is not needed for iOS9 and above.
http://useyourloaf.com/blog/unregistering-nsnotificationcenter-observers-in-ios-9/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.