Stripping dynamic constants

For localization, I have a module with about 500 constants in 10 different languages.
Most is general stuff like error messages, standard phrases and general words like ‘Advanced’, ‘OK’, ‘Convert’, ‘Start’, ‘Upgrade’ etc.

I use this module in different Apps but after compiling, everything is always included in the .lproj files in the …/Contents/Resources folder.

I saw <> but since that’s 2 yrs old, I don’t expect it to be fixed soon.

Is there some way to get the unused constants removed?

I’m even willing to delete them manually but there doesn’t seem to be an easy way to list the unused ones. ‘Analyze Project’ doesn’t show anything either.

You could copy the constants to an empty project, then delete them from the project in question and run analyze. Then you can look at all the missing items listed and copy them back in.

I would ask Thomas to add a feature into ARBed to get a report on unused Dynamic constants. Xojo doesn’t really help you very much when it comes to localization. Don’t get me wrong, the dynamic constants are nice but I seem to always be struggling with it.

Yes, I think that makes most sense.
I’m currently trying Jim’s suggestion. It works when cleaning up just before deployment but it’s a hassle to copy things around during development. It also won’t work for labels and captions set in the Inspector using #kConstant. I can work around that setting those in their .Open’s but it’s so easy to forget one.

I assume there must be a good reason why Xojo isn’t stripping them by default though. Or not showing warnings in Analyze. Same as it’s not warning for unused Methods and Globals.

“unused” is just not easy to do
Thomas wont have an easier time since you literally have to parse the code to know
And you have to take into account all #if Targets etc
And you have to know which target you are compiling for

For instance is SomeDynamicConstant “unused” in this code ?

 dim s as string
 #if TargetMacOS
         s = SomeDynamicConstant + s
  #elseIf TargetWindows
         s = s + SomeDynamicConstant

You CANNOT tell just by looking
I may be compiling for Linux, or iOS, or XojoCloud
Then it is
But if I’m compiling for macOS or Windows it isn’t

The ONLY way to do this kind of report is AT compile time (not debug time since that is always for the current platform you’re on) when all of those details are known

Well, I think that was the original intention. Strip dynamic constants so that the compiled App only has localized strings that are used.
Because that’s not happening, I was searching for alternatives to get them out. Like reporting unused Dynamic Constants at Analyze. But I see what you’re saying. Analyze is not the same as compiling/building.

Still looking for a way to get them out though.

when I’ve needed to do this in the IDE (which has several thousand localized strings) I’ll confess

  • I’ve opened BBedit
  • renamed EVERY dynamic constant starting with an x (regex search & replaces across many many files)
  • reopened the IDE project on OS X, Windows & Linux (all at the same time from the same svn working copy)
    Run each one and see what gets reported as missing

And yeah you’d think I could find a better way but its just not there
At some point maybe but not right now

In App Wrapper, you can strip unused languages, but it doesn’t know how to read a compiled binary and detect if a certain string is used or not used.

How do you know a language is unused??? Does that not depend on the user’s computer language?

As for unused constants:

Not at my Mac but Lingua can’t delete a language?

And wasn’t there a lingua replacement? Maybe by Thomas?

It’s not about stripping language files.
I have have a ‘general’ module with ~500 dynamic constants in 10 languages that I use in all my Apps.
But when I only use 100, the other 400 aren’t stripped from the final build.
Everything is always included in each .lproj file in the Resources folder.

When you include a module with your collection of methods and extends, everything that isn’t used is stripped. That’s not the case with dynamic constants.

Thanks for the clarification.

Is it worth stripping as they use a miniscule amount of space?

Do you really want to end up with different localization modules each containing different combinations of constants?

If it really bothers you then don’t use a module at all.

Subclass all controls, add a constant, and let each control deal with localization itself.

I didn’t say it’s about space.
Constants for completely unrelated Apps ended up in different deployed Apps. Texts about Saas, upgrades, product keys or client related stuff ended up in the Apps in the MAS.
My mistake because I incorrectly assumed they would get stripped the same way as unused methods.

And I don’t want to end up with different modules at all. I want to use 1 where possible. However, since Xojo doesn’t strip it for me, I was looking for another way to clean them up.

But no worries. I was only asking if anyone knew a way but it seems there isn’t other than manually weed them out.

Make a module GeneralLocalizations and one AppSpecificLocalizations?

In the “Other” options, you select which languages your application doesn’t use. Then App Wrapper strips the resources from anywhere within the application bundle.

Ah. Difference between use and implement. The user uses the language, the app implements it.

Sorry for being a pain in the behind :wink: it’s a proof-reading curse :stuck_out_tongue_winking_eye: