To answer my own question, here is my approach:
1. Add/enable this fragment in your Generate*.mwe2 file:
fragment = scoping.ImportURIScopingFragment {}
2. Add this code to *RuntimeModule:
public Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() {
return ImportUriGlobalScopeProvider.class;
}
public Class<? extends ImportUriResolver> bindImportUriResolver() {
return I18nImportUriResolver.class;
}
The important part is the "I18nImportUriResolver" which works like this:
public class I18nImportUriResolver extends ImportUriResolver {
private final static Logger log = Logger.getLogger( I18nImportUriResolver.class );
@Override
public String apply( EObject from ) {
if (I18nDslPackage.Literals.I1_8N_DOMAIN_MODEL.equals( from.eClass() ) ) {
I18nDomainModel model = (I18nDomainModel) from;
return apply( model );
}
return super.apply( from );
}
public String apply( I18nDomainModel model ) {
if( I18nDslJavaValidator.isBaseModel( model ) ) {
return null;
}
URI uri = I18nDslJavaValidator.getBaseURI( model );
log.debug( "Importing " + uri );
return uri == null ? null : uri.toString();
}
}
This checks whether the current node in the model is "I18nDomainModel". If so and if this isn't the base file, then the base URI is created by stripping the locale from the URI and the new URI is returned.
Xtext will then load the resource from this URI and add all exported symbols. Xtext knows which symbols to export since I reference some types with "[]" in my grammar:
That means all "BaseMessage" instances defined in the base file will be visible by the content of their "name" field.