Coder Social home page Coder Social logo

Ability to change Locale about swiftgen HOT 6 OPEN

diamid6 avatar diamid6 commented on June 19, 2024 1
Ability to change Locale

from swiftgen.

Comments (6)

diamid6 avatar diamid6 commented on June 19, 2024 1

Locale affects the rule for plurals in Localized.stringdict. You may check it with two locales which has different cases for one, two, many, other. If I change locale in runtime without changing in Settings App, Locale.current is still will be the same. This can lead to incorrect string format as the result because for definition the correct plural case will being use Locale.current but not Locale(identifier: <new_locale_identifier>).

from swiftgen.

BastianKusserow avatar BastianKusserow commented on June 19, 2024

I was just about to ask the same question. If an app has its own sense of how to localize their strings, I wonder if its correct that the String init from above gets the current locale as parameter. Apple is also not very specific about what happens with that locale (considering my format string has some string placeholders, I assume nothing will happen, but not sure about other types than strings?!).

from swiftgen.

BastianKusserow avatar BastianKusserow commented on June 19, 2024

Ah yeah, that makes total sense! Our app has its own sense of localization and I assume that will likely break if the OS locale is different from the one of the app, which makes that lookup function a little useless for us now. I know we can always create our own template, but that would be much nicer thb..

from swiftgen.

djbe avatar djbe commented on June 19, 2024

The built-in templates support custom lookupFunctions, so you can do whatever crazy locale stuff you'd like. I would NOT recommend it at all (see @diamid6 comment about inconsistencies), but I know how projects & client requirements work 🤷

Read the template docs here: https://github.com/SwiftGen/SwiftGen/blob/stable/Documentation/templates/strings/structured-swift5.md

from swiftgen.

BastianKusserow avatar BastianKusserow commented on June 19, 2024

While that's true, in the end, even when using the lookup function, the last line of the tr function is always return String(format: format, locale: Locale.current, arguments: args). There the result returned from the lookup function is passed to the String(format:locale:) initializer and the locale that's passed there cannot be changed. This can lead to unexpected behavior in some cases.

from swiftgen.

djbe avatar djbe commented on June 19, 2024

Ah right, well in that case you should use custom templates (see docs).

from swiftgen.

Related Issues (20)

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.