Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Using Plug-in properties API?
Using Plug-in properties API? [message #325653] Mon, 25 February 2008 12:20 Go to next message
Jan Kohnert is currently offline Jan KohnertFriend
Messages: 196
Registered: July 2009
Senior Member
Hello,

I want to use a plug-ins property file (plugin.properties with Manifest
entry = Bundle-Localization: plugin) for my own plug-in purposes.

Is there a API within eclipse for this?

Thanks!
Re: Using Plug-in properties API? [message #325674 is a reply to message #325653] Mon, 25 February 2008 16:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zx.us.ibm.com

> Is there a API within eclipse for this?

What do you mean? I'm confused at what your request is. Can you give an
example?

Cheers,

~ Chris
Re: Using Plug-in properties API? [message #325746 is a reply to message #325674] Tue, 26 February 2008 10:47 Go to previous messageGo to next message
Jan Kohnert is currently offline Jan KohnertFriend
Messages: 196
Registered: July 2009
Senior Member
Chris,

If I define a property within a plugin.properties file. For instance:
plugin.properties
views.myview.name = My View

and in plugin_de.properties
views.myview.name = Meine Ansicht

In plugin.xml I define:
<view name="%views.myview.name/>

If i do that, my views title will become 'My View' or 'Meine Ansicht'
dependant on enviroments settings.

Now, I've further strings used within the MyView class. For instacne a
labels text. Because it is quite handy to have all strings belonging to a
class at just one place, I want to store the labels text also inside the
propertiy file.
Just like:
plugin.properties
views.myview.name = My View
views.myview.label.text = A Label Text

and in plugin_de.properties
views.myview.name = Meine Ansicht
views.myview.label.text = Eine Namesinschrift

Now I'm at the point wher I first wrote my post.
I want to assign the string stored in the property file to the labels text.
Label label = new Label(parent SWT.NONE);
label.setText(???)

My problem is, that I do not know how to access the property file using
Eclipse API.
I offcause I could use label.setText("%views.myview.label.text"), but this
would just set the labels text to "%views.myview.label.text" and not to
the value assigned in the file ("A Label Text", or "Eine Namesinschrift")

Hope I could make myself clear this time :)

Jan
Re: Using Plug-in properties API? [message #325754 is a reply to message #325746] Tue, 26 February 2008 13:37 Go to previous messageGo to next message
Manuel Selva is currently offline Manuel SelvaFriend
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
Hi,

Take a look on the JDT / PDE externalyze string function. To do this just
right click inside the Java editor and the contextual menu should propose
it somewhere.

When doing this a simple Message class is automatically created and is
able to read a given properties file. You could may be reuse this class ...

Hope this help

Manu
http://manuelselva.wordpress.com


Re: Using Plug-in properties API? [message #325763 is a reply to message #325746] Tue, 26 February 2008 15:13 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

There is no API to access that file ... that's not the way you do view i18n.

You could ... get your OSGi Bundle and get the Bundle-Localization
header, and then try and get the .properties file using getResource(*)
and then use ResourceBundle to try and load things from it ... it sounds
painful.

The eclipse best practice is to place localization for plugin.xml and
MANIFEST.MF into the plugin.properties. Localization for UI code should
go in a NLS extending class and matching properties file in the
directory that defines the ViewPart (for example). As Manuel mentioned,
there's pretty good tooling that allows both a ResourceBundle and
eclipse-NLS class based approach.

Later,
PW



--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Using Plug-in properties API? [message #325792 is a reply to message #325763] Wed, 27 February 2008 10:45 Go to previous messageGo to next message
Jan Kohnert is currently offline Jan KohnertFriend
Messages: 196
Registered: July 2009
Senior Member
Thanks for your answer Paul.

Sadly I do not understand this best practice solution.
Mainly because of two reasons.
First:
I've a product running on different language environments. The product is
set up at a customer by fitters having in general very view knowlage about
eclipse good practiceses. What they want is just one place where every
string used by the product is defined so that they can change it to the
customers wishes. It is not reasonable to let them scan each package for
property files just to performe a view minor tweaks.

Second:
A parts name, a commands desciption,a menus entry and so on. There are all
somehow part of the UI. I define their names and descriptions within the
plugin.property file. Usage of translated versions of these strings is
done automaticly by eclipse.
Why is custom generaded UI code (such as view content) less important that
it is nor a good practice to let it participate on this very handy
mechanism?
If this was possible, transaltion and customization of a whole plugin
could be done by using just one file!

Even when it might not be best practice, at least here should be some API
to access the plugin.properties file.
As you sad, finding and parsing the file manually would be painfull.
I'm questioning my self how reading of this file is done in eclipse. I
tried to debug my self into it, but could not finde the right place.

I'would open a request on this (creating API). But only if the eclipse
part that is responsible for reading the properties file is not
accessible. What means that I first have to finde it :)

Jan
Re: Using Plug-in properties API? [message #325798 is a reply to message #325792] Wed, 27 February 2008 13:45 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Jan Kohnert wrote:
> Thanks for your answer Paul.
>
> Sadly I do not understand this best practice solution.
> Mainly because of two reasons.
> First:
> I've a product running on different language environments. The product
> is set up at a customer by fitters having in general very view knowlage
> about eclipse good practiceses. What they want is just one place where
> every string used by the product is defined so that they can change it
> to the customers wishes. It is not reasonable to let them scan each
> package for property files just to performe a view minor tweaks.

You do not make them scan packages. Adding new language packs in
eclipse is done by way of fragments i.e. a small directory structure
made entirely of the language property files and nothing else.

It's not difficult to find the 3 or 5 properties files in a small
directory structure.

But this bullet isn't about "understanding" the practice, this is more a
"why I think it might not work for me".

> Second:
> A parts name, a commands desciption,a menus entry and so on. There are
> all somehow part of the UI. I define their names and descriptions within
> the plugin.property file. Usage of translated versions of these strings
> is done automaticly by eclipse. Why is custom generaded UI code (such as
> view content) less important that it is nor a good practice to let it
> participate on this very handy mechanism?

the plugin.properties file is for translating information available from
the OSGi manifest and Equinox Extension Registry. Now some extension
points (like org.eclipse.ui.menus) take that information and use it to
instantiate UI elements, and that's why they're translated there.

But it is not a properties file for translating whatever you want, just
what comes out of the Extension Registry. Technically, the Extension
Registry has nothing to do with the UI (it just happens to be the
extensible mechanism that all eclipse plugins use to allow contributions
and to delay loading other plugins).

You can ask for API to access this file if you want ... but I suspect it
will be marked as WONTFIX (since it's not an appropriate use of this file).

Plus eclipse provides a very handy mechanism ... the NLS class + a
..properties file allows you to use constants in your ViewPart class
(say) which are easily scanned and index by the JDT environment. The
Externalize Strings wizard will create the class and properties file for
you, and by using these constants you can examine new strings that
appear during maintenance without fear of missing them because you
already have a number of strings in the class. There are many benefits
aside from this.


But if you really want to, check out
http://dev.eclipse.org/newslists/news.eclipse.platform/msg67 801.html ...
it shows how to manually load the standard localization file from a
bundle (amongst other things).

Later,
PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:cannot convert from URI to URI
Next Topic:How to bring to top without activating?
Goto Forum:
  


Current Time: Sat Nov 09 03:35:27 GMT 2024

Powered by FUDForum. Page generated in 0.03392 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top