I18N : Constants needed in constant (Java/GWT) - java

I I18N an application.
Part of it consists in I18N-ing the menus. That is OK.
With GWT I can use the Constants interface.
Now I have to I18N the help for the app, which includes some text referring to Menus.
So in these bigger constants, I need to use the menu constants.
Exemple :
I have a resource in the property file for I18N :
menuPlay = Play ...
Now I want to define another resource = some help text:
howToPlay = In order to start the game, go to the menu ??<resource menuPlay>??
In question marks above, I want to use the resource menuPlay.
When I want to translate eg in French, the two resources would be :
menuPlay = Jouer...
howToPlay = Pour démarrer le jeu, aller au menu ??<resource menuPlay>??
How can I do that (in Java / GWT) ?
I mean is there an off-the-shelf solution (which I could not find or think of). I don't want to code some specific solution that would combine both --in real time-- based on localized info.
This would help prevent inconsistencies when changing the menuPlay resource : no need to bother on changing the other resource howToPlay (high risks to forget).

Then you property is like
menuPlay = Play ...
howToPlay = In order to start the game, go to the menu {0}
while using
inorder to get menuPlay then in java you may using like resource.menuPlay();
now inorder to get howtoPlay
resource.howToPlay(resource.menuPlay()); //now {0} replaces with Play
you can do it for no.of arguments
howToPlay = In order to start the game, go to the menu {0} {1} ..etc
see message patterns

Related

How can I extract text from a flex container?

I'm a beginner in Java and I'm attempting to extract some text from a website. The text however is between two tags and when I use getByXPath to extract the text I get everything except the text I need.
This is the layout of the website I'm scraping from: Website HTML Layout
The two highlighted portions are the pieces of text I actually need.
And this is the code I've got so far:
List<HtmlElement> name = (List<HtmlElement>) page.getByXPath("//ul/li/a[#class='title']");
List<HtmlElement> subText = (List<HtmlElement>) page.getByXPath("//ul/li/p[#data-af=' (Secret)']");
This however results in two lists:
name - which has HtmlAnchor objects within
[HtmlAnchor[<a class="title" data-af="10" href="/a180775/daddys-home-achievement">], HtmlAnchor[<a class="title" data-af="11" href="/a180776/protector-achievement">], HtmlAnchor[<a class="title" data-af="12" href="/a180777/sinclairs-solution-achievement">]]
subText - which has HtmlParagraph objects within.
[HtmlParagraph[<p data-af=" (Secret)">], HtmlParagraph[<p data-af=" (Secret)">], HtmlParagraph[<p data-af=" (Secret)">], HtmlParagraph[<p data-af=" (Secret)">]]
URL if you want to take a look at the whole website: https://truesteamachievements.com/game/BioShock-2-Remastered/achievements
I need the lists to look something like these:
["Daddy's Home", "Protector", "Sinclair's Solution"]
["Found your way back to the ruins of Rapture.", "Defended yourself against Lamb's assault in the train station.", "Joined forces with Sinclair in Ryan Amusements."]
This is the Html library I'm using : https://htmlunit.sourceforge.io/apidocs/overview-summary.html
Appreciate any help.
The simplest way is using Stream API:
List<HTMLElement> htmlElementList = new ArrayList<>();//get your list in needed way
List<String> listOfTitles = htmlElementList.stream()
.map(HTMLElement::getTitle)
.toList();
More understanding, with foreach loop:
List<HTMLElement> htmlElementList = new ArrayList<>();
List<String> listOfTitles = new ArrayList<>();
for (HTMLElement htmlElement:
htmlElementList) {
listOfTitles.add(htmlElement.getTitle());
}
Not clear - which library you use for elements receiving. This is an example of the case if you use the org.w3c.dom library for HtmlElement definition. Otherwise - use the appropriate method for text receiving (except getTitle()), for example getText() - used for selenium WebElement, etc...

How to implement HighChart thousandsSep() for android(JAVA) on Hi-chart WordCloud

I would like to show tooltip on clicking on any word of Android Hi-chart Word-Cloud like 1,000 , currently it is showing like 1 000.
I had conversation with Hi-chart support team.
They suggested with this URL.
But unable to understand how to implement the same. I tried as below:
HILang hiLang = new HILang();
hiLang.setThousandsSep("3");
But setThousandsSep method accepts String type parameter only.
The default is a single space character which is why it is being shown as 3 100; a space after "3"
Try
hiLang.setThousandsSep(",");

Identify classes at run-time

I'm working in a project for Android using libGDX framework in which I show some examples of the use of three graphic libraries. Once started, the app must show a menu with a link for each sample, its title and a little description. For the time being, I'm creating all manually, declaring a new link for each sample, but as I will have a lot of samples and I'll add new ones in each app version, I would like to identify them and generate a new entry automatically.
The samples part is composed of an abstract class called Sample and a class for each sample that extends from Sample. How could I accomplish this? The requisites will be to have the possibility to identify all samples at run-time and get information about them (name, description, etc.) without the need of create an instance previously.
My actual options are use Annotations (don't know if it is possible or if I need an external library to search for this annotations at run-time) or use something like a JSON file. What do you think is the best way (I'm open to other solutions of course) to solve this problem?
I would recomend using XML and take the class you want to create as Tag so something like this:
<root>
<sampleimplement1 name ="sampleimplement1" descript="sample1 description" ..... more attributes here... />
<sampleimplement2 name ="sampleimplement2" descript="sample2 description" ..... more attributes here... />
<sampleimplement3 name ="sampleimplement3" descript="sample3 description" ..... more attributes here... />
</root>
This can now be parsed with the XmlReader of libgdx to a Element. So the element is not the root.
Last but not least you can iterate over the childs of the root and check what the name of the Tag is. Depending on the name you create a different implementation of your Sample.
XmlReader r = new XmlReader();
Element e = r.parse(xml);//<--- the XML as string also possible as file
for (int i = 0; i < e.getChildCount(); i++)
{
Element child = e.getChild(i);
switch(child.getName()){
case "sampleimplement1":
//create sample1
break;
....
....
}

How to remove unwanted menu contributions in eclipse rcp application?

I have made a eclipse RCP application, everything is working fine but i recently noticed the Refractor option in menu. I would like to get rid of it. I have the following in ActionBarAdvisor.java:
#Override
protected void fillMenuBar(IMenuManager menu) {
menu.add(createFile());
menu.add(createEdit());
menu.add(createNavigate());
menu.add(createProject());
menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(createWindow());
menu.add(createHelp());
}
The above functions add actions to menu as:
edit.add(undoAct);
and also undoAct is defined as:
private IWorkbenchAction undoAction
makeActions function has contents as:
#Override
protected void makeActions(IWorkbenchWindow window) {
undoAction = ActionFactory.UNDO.create(window);
undoAction.setText("Undo Menu");
register(undoAction);
}
I found a suggestion which said to use hideActionSets to hide the menu. But I could not hide the entire menu but just its actions!
Remove "File, edit,...etc" menus from Eclipse RCP application
How to remove Refractor option now?
Thank you.
You can use activities, as described here.
First, you will need to find the ID of the menu:
Use the Plug-In Spy
The first way is to use the Plug-In Spy. Press alt-shift-F2 and click on a
menu item or toolbar button that you want to be hidden. If there is an ID
string under the heading "active action definition identifier" then you are
in luck. This item has been added using the Command Extension and you can
use this ID as the pattern argument for the Activities Extension. But not
all items that have been added using the Command Extension present their ID
string to the plug-in spy.
As a side note, the ID strings are period separated. For instance the ID for
a button might be "org.eclipse.ui.navigate.backwardHistory". Regular
expressions use the period to stand for any character. Luckily the period
used as a wild card matches with actual period characters so you don't need
to escape them if you don't want to. I find it makes it a bit easier to read
if they are not escaped and it is highly unlikely it will cause any
ambiguous matches.
Use the Plug-In Registry and plugin.xml files
The second way is to use the Plug-In Registry. You can open this view by
going to:
Window/Show View.../Other/Plug-in Development/Plug-In Registry
What you would like to do is to try to get a couple pieces of information:
a) the plugin that is contributing the UI element
b) information about what kind of extension the plugin is using to create
the UI element
If there is a very unique word associated with the UI element or its tool
tip then you can use this in the Plug-In Registry's filter field to try to
nail down which plug-in is contributing the UI element. The filter field is
not a very powerful tool so it can be a bit frustrating to use. It does not
allow wildcards and does not match space characters.
When you track down which plug-in is contributing the UI element then you
open the the plug-in in question from the Plug-Ins view which is found
grouped with the Package Explorer in the Plug-in Development perspective.
Then go to the Extensions tab and search for the ID string which can usually
be found in either a usage of the Command or ActionSet extension. If the UI
element is added using an ActionSet then you prefix the plug-in ID to UI ID
in the pattern argument given to the Activities Extension. For example
org.eclipse.ui.actionsets.foo becomes the pattern
org.eclipse.ui/org.eclipse.ui.actionsets.foo.
Then create a new Activity which will never be activated and a corresponding activityPatternBinding with the id you found in the last step. It will look like this in your plugin.xml:
<extension point="org.eclipse.ui.activities">
<activity id="myActivity" name="MenuHidingActivity">
<enabledWhen>
<with variable="activePartId">
<equals value="nonExistentPartId"></equals>
</with>
</enabledWhen>
</activity>
<activityPatternBinding activityId="myActivity" pattern="menuItemID">
</activityPatternBinding>
</extension>

Load a string resource based on selected MenuItem resource ID - Android JAVA

I am writing my first Android app. It will have hundreds of menu links that will change with each version released. I am looking for a way to process the onclicks based on the Resource ID.
Menus are defined in XML like so:
<item android:id="#+id/Spring_2013" android:title="Spring 2013" android:showAsAction="ifRoom|withText" />
The onclicks will load a URL stored in strings.xml:
<string name="Summer_2013">file:///android_asset/catalog/current/genadmissionreq.html</string>
So, seems like all I need is a simple, single onclick method that loads whatever string is needed based on the selected Resource ID. The MenuItem ID is ALWAYS equal to the URL string ID in my code. So, without using hundreds of if() or switch/case statments, cant I just say:
String url = getString("R.string." + menuItem.getItemId());
Obviously that assignment wont work for a number of reasons. But you get the idea right? So, how CAN I make this work?
Im sorry for the newb question. I know it should be simple but I've been reading for days and cannot find any way to do this without an if() statement for EVERY menu item. That method would make the weekly updates a nightmare!
Try using getIdentifier()
String title = menuItem.getTitle().toString().replace(' ', '_');
id = getResources().getIdentifier(title, "string", getPackageName());
String string = getString(id);
The first line fetches Spring 2013 and converts it to Spring_2013.
The second line builds "R.string." with whatever the title is, in this case "R.string.Spring_2013".
The third line simply fetches the String resource.

Categories