Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Externalization of check messages
Externalization of check messages [message #526433] Sun, 11 April 2010 00:20 Go to next message
Elhamlaoui Mahmoud is currently offline Elhamlaoui MahmoudFriend
Messages: 268
Registered: March 2010
Senior Member

HI,

I wonder if there is a way to enable the externalization of messages shown when there is an error or a warning with check so i can change them easily after

Best regards
mahmoud
Re: Externalization of check messages [message #526452 is a reply to message #526433] Sun, 11 April 2010 09:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hello mahmoud,

i don't know a direct way to do this but you can easy achive something similar by moving the message producing part of the check to a separate extension file.

metamodel/checks.chk
extension metamodel::messages;

context metamodel::Model ERROR msgABC() :
	false;


metamodel/messages.ext
String msgABC() : "There is an error";


or with some extra stuff you could even use java resource bundles

package metamodel;

import java.text.MessageFormat;
import java.util.List;
import java.util.ResourceBundle;

public class I18NHelper {
	
	public static String msg(String key, List<Object> args) {
		return MessageFormat.format(ResourceBundle.getBundle("messages").getString(key), args.toArray());
	}

}


messages.properties
ABC=Böser Fehler


String msg(String key, List args) :
	JAVA metamodel.I18NHelper.msg(java.lang.String, java.util.List);


context metamodel::Model ERROR msg("ABC",{}) :
	false;


may not be perfect but working


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Externalization of check messages [message #526499 is a reply to message #526452] Sun, 11 April 2010 22:51 Go to previous messageGo to next message
Elhamlaoui Mahmoud is currently offline Elhamlaoui MahmoudFriend
Messages: 268
Registered: March 2010
Senior Member

Hi Christian,

Thanks for the reply, but i was looking exactly for your second answer, can i have more details about java resource bundles, i dont have any idea how to perform this,

thanks
mahmoud
Re: Externalization of check messages [message #526516 is a reply to message #526499] Mon, 12 April 2010 06:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
ResourceBundle is a std java lib class so have a look at the javadoc for this

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 12 April 2010 06:22]

Report message to a moderator

Re: Externalization of check messages [message #529684 is a reply to message #526516] Mon, 26 April 2010 18:26 Go to previous messageGo to next message
Elhamlaoui Mahmoud is currently offline Elhamlaoui MahmoudFriend
Messages: 268
Registered: March 2010
Senior Member

hi Christian,

i tried to perform the example but i couldnt make it woks.
I create the bundle but i dint understand how to make it work with I18NHelper
Quote:

package com.validation;

import org.eclipse.osgi.util.NLS;

public class Messages extends NLS {
private static final String BUNDLE_NAME = "com.netfective.validation.messages"; //$NON-NLS-1$
public static String ddd_0;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages() {
}
}



in my extension file this this :
Quote:

String msg(String key, List args) :
JAVA com.validation.I18NHelper.msg(java.lang.String, java.util.List);




end last in my check file i have :
Quote:

context DSLMetaModel::Attribute ERROR msg("ddd_0",{}) :
this.type.name!= null;



i know that its my fault because i forget something

mahmoud
Re: Externalization of check messages [message #529812 is a reply to message #529684] Tue, 27 April 2010 10:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi, you mix Java Resource bundles (I18NHelper) with Eclipse NLS (Your Messages class that is nowhere used). That is the problem.
Just have a look at the ResourceBundle JavaDoc for how to configure it (a file messages[_locale].properties in classpath since the code says ResourceBundle.getBundle("messages"))


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 27 April 2010 10:58]

Report message to a moderator

Re: Externalization of check messages [message #530635 is a reply to message #529812] Fri, 30 April 2010 11:53 Go to previous message
Elhamlaoui Mahmoud is currently offline Elhamlaoui MahmoudFriend
Messages: 268
Registered: March 2010
Senior Member

Hello christian,

i would like to share my example that works pretty fine, thanks to you:

Quote:

package com.sms;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Messages {
private static final String BUNDLE_NAME = "com.sms.messages";

private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
.getBundle(BUNDLE_NAME);

private Messages() {
}

public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}



the messages.proprties:
Quote:

test.1=element must have a name



the extension file :
Quote:

String msg (String s):
JAVA com.sms.Messages.getString(java.lang.String)
;



and the check file :
Quote:

context MetaModel::Cars ERROR msg('test.1')
this.name!=null
;



mahmoud
Previous Topic:Acceleo : White space handling
Next Topic:[check] Problem with the metamodel
Goto Forum:
  


Current Time: Tue Apr 23 09:17:12 GMT 2024

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

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

Back to the top