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

iOS/Mac Catalyst image localization #16734

Closed
davidbritch opened this issue Aug 14, 2023 · 9 comments · Fixed by #23269
Closed

iOS/Mac Catalyst image localization #16734

davidbritch opened this issue Aug 14, 2023 · 9 comments · Fixed by #23269
Assignees
Labels
area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer fixed-in-8.0.70 fixed-in-9.0.0-preview.7.24407.4 i/great-reporter This issue is opened by an author who is known to open high-quality issues platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@davidbritch
Copy link
Contributor

davidbritch commented Aug 14, 2023

Description

The technique for localizing images on iOS are well known. It involves creating folders with the locale name, followed by .lproj, with the images in these folders. These would normally go in a Resources folder. So for MAUI I translated this to the Platforms\iOS\Resources folder:

image

The images have a build action of BundleResource.

This doesn't work for iOS, or on Mac Catalyst (using the equivalent MacCatalyst folder).

What does work is putting the .lproj folders in the root of the MAUI project:

image

Localized images are then displayed (on both iOS + MacCat).

While it works it makes me feel dirty having the root of your project contaminated with Apple only resources.

UPDATE: @rolfbjarne has told me that updating the .csproj to include <IPhoneResourcePrefix>Platforms/iOS/Resources</IPhoneResourcePrefix> makes localised images, contained in that specific folder, work on iOS + MacCat.

Steps to Reproduce

  1. Run attached sample on iOS.

Link to public reproduction project repository

https://github.com/davidbritch/dotnet-maui-issues/tree/main/LocalizationDemo

Version with bug

7.0.92

Is this a regression from previous behavior?

Don't think this has ever worked!

Affected platforms

iOS, macOS

Did you find any workaround?

Place .lproj folders in the root of your MAUI project.

OR (better)

Update your .csproj with the following:

	<PropertyGroup Condition="$(TargetFramework.Contains('-ios'))">
		<IPhoneResourcePrefix>Platforms/iOS/Resources</IPhoneResourcePrefix>
	</PropertyGroup>

	<PropertyGroup Condition="$(TargetFramework.Contains('-maccatalyst'))">
		<IPhoneResourcePrefix>Platforms/MacCatalyst/Resources</IPhoneResourcePrefix>
	</PropertyGroup>
@davidbritch davidbritch added the t/bug Something isn't working label Aug 14, 2023
@ghost ghost added the i/great-reporter This issue is opened by an author who is known to open high-quality issues label Aug 14, 2023
@rolfbjarne
Copy link
Member

MAUI already sets IPhoneResourcePrefix, but it happens too late:

<IPhoneResourcePrefix>$(iOSProjectFolder)Resources</IPhoneResourcePrefix>

<IPhoneResourcePrefix>$(MacCatalystProjectFolder)Resources</IPhoneResourcePrefix>

@rolfbjarne
Copy link
Member

In particular it must happen before Xamarin.Shared.props is imported in line 211 here:

https://gist.github.com/rolfbjarne/b194bc4d4d345425eee1a17fc0523ab6#file-gistfile1-txt-L211

currently it happens in Microsoft.Maui.Controls.SingleProject.targets at line 246:

https://gist.github.com/rolfbjarne/b194bc4d4d345425eee1a17fc0523ab6#file-gistfile1-txt-L246

@ghost
Copy link

ghost commented Aug 15, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Aug 23, 2023
@XamlTest
Copy link

Verified this on Visual Studio Enterprise 17.8.0 Preview 1.0. Repro on iOS 16.4 and Windows 11 .NET 8, not repro on Android 13.0-API33 with below Project:
LocalizationDemo.zip

iOS:
image
Android:
image

@ArchimedesFTW
Copy link

@davidbritch does localization of Info.plist work for you with your proposed workaround?

I want to ask for location permission with localized text.

I moved fr.lproj to the project root to get the flag visible on iOS. I added InfoPlist.strings in that folder but it won't show the different text. Instead it shows the text that I added in the Info.plist.

image

Any suggestions?

@davidbritch
Copy link
Contributor Author

@ArchimedesFTW It worked for me at the time of writing. But there've been multiple releases since then, and I've not tried it since.

@janusw
Copy link
Contributor

janusw commented Mar 27, 2024

@davidbritch does localization of Info.plist work for you with your proposed workaround?

I want to ask for location permission with localized text.

FYI, I got the permission localization working by placing the lproj folders here (with MAUI 8.0.14):

	<ItemGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
		<BundleResource Include="Resources\de.lproj\InfoPlist.strings" />
	</ItemGroup>

@janusw
Copy link
Contributor

janusw commented Mar 27, 2024

FYI, I got the permission localization working by placing the lproj folders here (with MAUI 8.0.14):

	<ItemGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
		<BundleResource Include="Resources\de.lproj\InfoPlist.strings" />
	</ItemGroup>

Note that this location is slightly different from the one in the workaround mentioned in the original report (i.e. I'm placing the lproj folders into Resources, and not directly into the root folder).

Also, I can confirm that the second workaround works well with permission localization: If the lproj folders are in Platforms\iOS\Resources, you need the additional

<IPhoneResourcePrefix>Platforms/iOS/Resources</IPhoneResourcePrefix>

in your csproj.

@tdamir
Copy link

tdamir commented Apr 17, 2024

In my case a working solution is to move files from Platforms/iOS/Resources to root/Resources folder OR move them to Resources/raw but then there is no need for <BundleResource> include.

Keeping the files in Platforms/iOS/Resources and adding the <IPhoneResourcePrefix>Platforms/iOS/Resources</IPhoneResourcePrefix> did't work for me. When I tried to publish/archive the project, it complained about not finding a generated Info.Plist file. Also, I have noticed that there were some warnings/errors like "The given path's format is not supported" or something like that while building the project.

I'm using Visual Studio Version 17.10.0 Preview 3.0. and MAUI 8.0.14.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer fixed-in-8.0.70 fixed-in-9.0.0-preview.7.24407.4 i/great-reporter This issue is opened by an author who is known to open high-quality issues platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants