Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.htmlkit.localization.set is getting overridden #124

Open
dev-onepayclick opened this issue Jun 18, 2023 · 11 comments
Open

app.htmlkit.localization.set is getting overridden #124

dev-onepayclick opened this issue Jun 18, 2023 · 11 comments
Labels
bug Something isn't working localization Includes the localization needs attention rendering v3

Comments

@dev-onepayclick
Copy link

Hi,

Even tho i'm setting the locale using app.htmlkit.localization.set(locale: "pt") I keep getting the error .missingTables because the currentLocale keeps defaulting to my browser's locale "en".

Not sure it's a bug or I'm doing something wrong 😄

@mattesmohr
Copy link
Member

Hey,

I can take a look tonight, when I am back home from work. I guess you are using the alpha?

Or wich release version do you use exactly?

@mattesmohr
Copy link
Member

mattesmohr commented Jun 19, 2023

@dev-onepayclick Did you set the source directory too?

app.htmlkit.localization.set(source: currentDirectory)

How does your folder structure look like? Something like this?

| Localization
| - en-GB
| - - translations.strings

@dev-onepayclick
Copy link
Author

Hey, sorry for the late response.

I fixed the folder structure. But then I get a different error. MissingKey.
I wanted to force the use of

| Localization
| - pt-BR
| - - translations.strings

so I called app.htmlkit.localization.set(locale: "pt-BR") but the library still defaults to en-CA.

Also, the error message is MissingKey but it doesn't tell the key that is missing.

@mattesmohr
Copy link
Member

No problem. 👍 Can you give me an example, what your translations.strings is build up, so I can reproduce your issue. That would be great.

I think the second issue is on me. You can rename the folder pt-BR to pt and use app.htmlkit.localization.set(locale: "pt") for now. The localization does not know the Locale pt-BR yet.

I will fix it.

@dev-onepayclick
Copy link
Author

dev-onepayclick commented Jul 15, 2023

Thank you very much 🙏🏻
Also, is there any way to opt out of localization?

@mattesmohr
Copy link
Member

mattesmohr commented Jul 15, 2023

I am not sure I understand. You don't need to use the localization.

Can you expand your thought a bit more? What would you like to do?

@dev-onepayclick
Copy link
Author

This is my current setup
image

image

image

But it seems it is still defaulting to en-CA. I changed the folder to "pt" as you suggested but it still goes uses "en-CA"

@dev-onepayclick
Copy link
Author

I am not sure I understand. You don't need to use the localization.
oh sorry. I was just curious, in case I needed to opt out of a translation for some specific case.
But I figured I can do

Label { "Something"}

in case I need to avoid localizing it.

and if I want it localized I do Label("Something"

@mattesmohr
Copy link
Member

The language and region on your device is English Canadian, right? I wrote the localization to take the device settings at first. But I guess it is too prominent... Maybe it needs a change. I will rethink it.

In your case it uses Portuguese only as fallback, you know. Is it what you want? Or should Portuguese be your first language of choice?

By the way, I think app.htmlkit.localization.set(source: URL(fileURLWithPath: "Localization")) is not right, does it work? It should be "Sources/Your Projectname/Localization/". At least on a Mac system.

Back to the Portuguese locale.

The current order for the localization is environment locale > device setting > application setting (alias fallback). That said...

  1. import HTMLKit
  2. application.htmlkit.environment.locale = Locale(tag: .portuguese)

would force the localization to use Portuguese.

or

Html {
}
.environment(key: \.locale, value: Locale(tag: .portuguese))
Paragraph("hello")
        .environment(key: \.locale)

should do the same.

@mattesmohr
Copy link
Member

in case I need to avoid localizing it.

and if I want it localized I do Label("Something"

Thats exactly how it works right now.

@mattesmohr mattesmohr added needs attention rendering bug Something isn't working labels Jul 15, 2023
@dev-onepayclick
Copy link
Author

By the way, I think app.htmlkit.localization.set(source: URL(fileURLWithPath: "Localization")) is not right, does it work? It should be "Sources/Your Projectname/Localization/". At least on a Mac system.

Yep, it seems to work. Its running on Docker tho. Haven't tried on Mac.

Yes I'm writing the webpage for a Portuguese audience :)

Thanks for the tips 🙏🏻 I totally forgot about the .environment thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working localization Includes the localization needs attention rendering v3
Development

No branches or pull requests

2 participants