Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » Externalization of check messages
Externalization of check messages [message #526433] Sat, 10 April 2010 20:20 Go to next message
Eclipse UserFriend

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 05:46 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Externalization of check messages [message #526499 is a reply to message #526452] Sun, 11 April 2010 18:51 Go to previous messageGo to next message
Eclipse UserFriend

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 02:21 Go to previous messageGo to next message
Eclipse UserFriend
ResourceBundle is a std java lib class so have a look at the javadoc for this

[Updated on: Mon, 12 April 2010 02:22] by Moderator

Re: Externalization of check messages [message #529684 is a reply to message #526516] Mon, 26 April 2010 14:26 Go to previous messageGo to next message
Eclipse UserFriend

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 06:55 Go to previous messageGo to next message
Eclipse UserFriend
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"))

[Updated on: Tue, 27 April 2010 06:58] by Moderator

Re: Externalization of check messages [message #530635 is a reply to message #529812] Fri, 30 April 2010 07:53 Go to previous message
Eclipse UserFriend

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: Mon Jun 30 17:58:22 EDT 2025

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

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

Back to the top