libs-base icon indicating copy to clipboard operation
libs-base copied to clipboard

Localization: Add support for plist-based `.strings` files

Open hmelder opened this issue 8 months ago • 4 comments

hmelder avatar May 01 '25 05:05 hmelder

@rfm this is also supported in recent MacOS versions

hmelder avatar May 27 '25 08:05 hmelder

If it parsed but produced the wrong information, log an error because the file is wrong. If it parsed and produced the right information, use it.

How can I verify this using +propertyListFromData:mutabilityOption:format:errorDescription:? Since errorDescription is just a string, it doesn't provide details about the error. This means I can't reliably determine the type of error that occurred. The only option in case of an error is to continue execution, which can be unpredictable. For instance, if parsing fails due to a syntax error in the plist, the method might continue and log confusing or misleading warnings.

hmelder avatar Jun 03 '25 07:06 hmelder

I'm not sure the order in which you get error information is much of a problem, but while looking at this I realised that there already existed a private function for getting strings table content (and NSBundle wasn't using it for some reason), so I tweaked that to call +propertyListFromData:mutabilityOption:format:errorDescription: after failing with the standard strings file parsing and simplified (removed quite a bit of code) NSBundle by using it. I also added a tiny testcase for it. Does it meet your needs?

rfm avatar Jun 03 '25 11:06 rfm

But id GSPropertyListFromStringsFormat(NSData *data) GS_ATTRIB_PRIVATE; does not really solve the problem:

Since errorDescription is just a string, it doesn't provide details about the error. This means I can't reliably determine the type of error that occurred. The only option in case of an error is to continue execution, which can be unpredictable

Something like +propertyListFromData:mutabilityOption:format:error: and then continue if the blob was not recognized as a property list.

hmelder avatar Jun 10 '25 08:06 hmelder

@rfm

hmelder avatar Jun 22 '25 15:06 hmelder

it doesn't provide details about the error. This means I can't reliably determine the type of error that occurred.

It seems to me that, at this point (we have determined that the file exists and have loaded it in) there is only one possible error: the content of the file cannot be parsed as a property list (ie it's not valid format in some way).

Certainly there's no obvious correct set of additional error information we can/should provide.

rfm avatar Sep 15 '25 08:09 rfm

Closing this since the functionality all seems to be there. We can't really know in detail why parsing failed, but if we just want to know what the best guess is for the format of the file, we can call +propertyListWithData:options:format:error: to get that.

rfm avatar Oct 30 '25 10:10 rfm