|
Replies:
14
-
Pages:
1
-
Last Post:
8 Apr 20, 16:00
Last Post By: JeffTucker
|
|
|
Posts:
8,039
Registered:
31-Jan-2006
|
|
|
Selectable HTML lang attribute
Posted:
7 Apr 20, 00:39
|
|
|
Occasioned by the discussion in this thread: https://jalbum.net/forum/thread.jspa?threadID=56099
I cribbed the routines from E+, as ctwist recommended, and started tinkering.
The first problem is that my skins don't have any text files for language support - I won't bore you with why that's true, but it has to do with the lack of translators, the frequency of UI changes, and so on. In short, it's a clumsy mechanism that's not manageable for a free-lance skin developer.
So, I switched to grabbing the list of supported languages from the jAlbum program directory, and immediately encountered a little oddity. There is, of course, no texts_en.properties file! So, I needed to add that to the generated list. OK, messy but do-able.
Next, I realized that I didn't want to pick up the system language choice as the default, but rather the jAlbum language choice. Easy enough - just grab Config.getConfig().getInterpretedLanguage(); So far, so good.
But then I got to the really interesting part, making the JComboBox editable. Here's where the difference between an interpreted onload.bsh and a compiled UI bites you on the butt. As soon as you set that item to be editable, Java helpfully inserts a blank entry on the list of choices - BeanShell does not. And guess what - you can't then force a setSelectedItem() on it. It stubbornly insists upon defaulting to the blank entry.
For now, I'm punting, and taking a simpler approach. But if anyone wants something to play with....
|
|
|
Posts:
8,039
Registered:
31-Jan-2006
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 01:07
in response to: JeffTucker
|
|
|
Found the answer, but don't understand it at all.
This problem goes away if I don't include the variable in SkinModel.java. Even entering it without a default value causes the misbehavior: String htmlLanguage;
Somewhere in there, the jAlbum core is doing me a "favor."
|
|
|
Posts:
474
Registered:
27-Sep-2003
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 01:49
in response to: JeffTucker
|
|
|
|
I have a more recent version of the code that I offered. This is compiled, but not published yet. I am not seeing the behaviour that you described. There is no blank entry in the list and I can enter a value that is not in the list.
Here it is. I haven't pasted it into the message because the crappy forum software strips off some essential characters.
|
|
|
Posts:
8,039
Registered:
31-Jan-2006
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 02:04
in response to: ctwist
|
|
|
I believe you'll find that that doesn't actually work. If you specify a default value in SkinModel.java, that ends up always being the default choice, no matter what language you've chosen in jAlbum. It overrides the setSelectedItem() result. Strangely, it works if you don't make the field editable.
Try it with your code. Go into the jAlbum preferences and choose Deutsch or français. The skin's JComboBox ignores your choice, always defaulting to en.
ETA: Other than this little bit of weirdness, I've got it working. It assembles the list from the jAlbum supported languages, adds "en", then sorts the result to populate the JComboBox. Then it grabs the chosen jAlbum language to set the default. You can enter your own code if the one you want isn't in the list.
Leaving the variable out of SkinModel.java would create a problem only if someone is running purely in console mode - I suspect you'd end up with an empty ${htmlLanguage} in that case. Maybe not worth fixing.
|
|
|
Posts:
8,039
Registered:
31-Jan-2006
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 02:34
in response to: JeffTucker
|
|
|
|
What the pieces look like, attached.
BTW, if you're compiling your UI, it's time to start using anonymous inner classes. That makes it easy to move whole chunks of the UI around without having to do a bunch of boring editing. No more: generalPanel.add("tab", ui.language);
With anonymous inner classes, you don't have to specify the panel name, so if you want to move the items elsewhere, it's just cut/paste. See attached file.
If you do this with an interpreted onload.bsh, however, skin loading takes forever. BeanShell doesn't handle it well
|
|
|
Posts:
474
Registered:
27-Sep-2003
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 04:22
in response to: JeffTucker
|
|
|
I believe you'll find that that doesn't actually work.
That's why it's not published; I have not done detailed testing.
Leaving the variable out of SkinModel.java would create a problem only if someone is running purely in console mode - I suspect you'd end up with an empty ${htmlLanguage} in that case. Maybe not worth fixing.
I have never tested console mode and probably never will. If it works, great. If it doesn't, too bad.
|
|
|
Posts:
474
Registered:
27-Sep-2003
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 04:27
in response to: JeffTucker
|
|
|
BTW, if you're compiling your UI, it's time to start using anonymous inner classes.
Looks interesting. Your timing is good (a new release on the near horizon). I will play with it tomorrow.
If you do this with an interpreted onload.bsh, however, skin loading takes forever. BeanShell doesn't handle it well
Not a concern for my in-progress or future development.
|
|
|
Posts:
3,442
Registered:
18-Oct-2002
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 11:52
in response to: ctwist
|
|
|
|
I don't think I can reproduce the problem. I added a "lang" JComboBox to Minimal, added a SkinModel with a default value (not the 1:st item in the list) and made the "lang" JComboBox editable. No change, i.e. the JComboBox still respects the default value set in the SkinModel upon skin loading (for instance when selecting that skin). Any value from the corresponding project has naturally priority. I've attached my test version here.
|
|
|
Posts:
8,039
Registered:
31-Jan-2006
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 13:50
in response to: davidekholm
|
|
|
Choose en as your jAlbum language, then load the skin. Yes, that field defaults to de. Kind of not what we're after.
ETA: Try adding these: lang.setEditable(true);
lang.setSelectedItem(Config.getConfig().getInterpretedLanguage());
ETAETA: In fact, setting it editable doesn't really matter. The key is that if there's a default value in SkinModel.java, even an empty one, you can't set a different default with setSelectedItem().
|
|
|
Posts:
3,442
Registered:
18-Oct-2002
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 14:26
in response to: JeffTucker
|
|
|
What if you set the value of "lang" in SkinProperties to Config.getConfig().getInterpretedLanguage() ?
|
|
|
Posts:
8,039
Registered:
31-Jan-2006
|
|
|
Re: Selectable HTML lang attribute
Posted:
7 Apr 20, 14:39
in response to: davidekholm
|
|
|
That doesn't seem to do anything, under any circumstances.
This isn't really a huge problem. Simply not including lang in SkinModel.java takes care of it. If the user has created a project in the application, the selected value will be saved with the project, and making the album in console mode will work just fine.
The only problem would occur if the user tries to generate an album in console mode without referencing a project file, i.e., accepting all the defaults. Tough to imagine someone wanting to do that, and even if he did, as long as the skin is doing only something simple with the value, like: <html lang="${lang}">
... the worst that can happen is that the output page will end up with an empty attribute, which is not really an HTML error.
But in other contexts, the inability to set a selected item on a JComboBox could be problematic. It's OK if you're doing something in a StateMonitor(), however, triggered by some other event. That's probably why we've never run into this before.
|
|
|
Posts:
474
Registered:
27-Sep-2003
|
|
|
Re: Selectable HTML lang attribute
Posted:
8 Apr 20, 01:48
in response to: JeffTucker
|
|
|
BTW, if you're compiling your UI, it's time to start using anonymous inner classes.
I followed your advice. Much cleaner!
|
|
|
Posts:
8,039
Registered:
31-Jan-2006
|
|
|
Re: Selectable HTML lang attribute
Posted:
8 Apr 20, 01:52
in response to: ctwist
|
|
|
Yup, once you've had anonymous inner classes, you never go back.
That's a slogan that doesn't have much of a ring to it, but it's true nonetheless.
|
|
|
Posts:
474
Registered:
27-Sep-2003
|
|
|
Re: Selectable HTML lang attribute
Posted:
8 Apr 20, 14:34
in response to: JeffTucker
|
|
Correct |
|
|
Solution to the language problem:
In SkinModel.java: import se.datadosen.jalbum.Config;
public String language=Config.getConfig().getInterpretedLanguage();
|
|
|
|
Legend
|
|
Forum admins
|
|
Helpful Answer
|
|
Correct Answer
|
|