Java Code Examples for org.pentaho.metadata.model.concept.types.LocalizedString#getLocalizedString()

The following examples show how to use org.pentaho.metadata.model.concept.types.LocalizedString#getLocalizedString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalizationUtil.java    From pentaho-metadata with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void exportLocalizedPropertiesRecursively( Properties props, IConcept parent, String locale ) {
  for ( String propName : parent.getChildProperties().keySet() ) {
    if ( parent.getChildProperty( propName ) instanceof LocalizedString ) {
      // externalize string
      String key = stringizeTokens( parent.getUniqueId() ) + ".[" + escapeKey( propName ) + "]";
      LocalizedString lstr = (LocalizedString) parent.getChildProperty( propName );
      String value = lstr.getLocalizedString( locale );
      if ( value == null ) {
        value = "";
      }
      props.setProperty( key, value );
    }
  }
  if ( parent.getChildren() != null ) {
    for ( IConcept child : parent.getChildren() ) {
      exportLocalizedPropertiesRecursively( props, child, locale );
    }
  } else {
    if ( logger.isDebugEnabled() ) {
      logger.debug( "concept " + stringizeTokens( parent.getUniqueId() ) + " does not have children" );
    }
  }
}
 
Example 2
Source File: LocalizedStringConceptMapper.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param value
 * @param type
 * @return
 */
public Object getValue( final Object value, final Class type, final DataAttributeContext context ) {
  if ( value == null ) {
    return null;
  }

  if ( value instanceof LocalizedString == false ) {
    return null;
  }

  if ( type == null || Object.class.equals( type ) || LocalizedString.class.equals( type ) ) {
    if ( value instanceof LocalizedStringWrapper ) {
      return value;
    }
    return new LocalizedStringWrapper( (LocalizedString) value );
  }

  if ( String.class.equals( type ) == false ) {
    return null;
  }

  final LocalizedString settings = (LocalizedString) value;
  final Locale locale = context.getLocale();
  final String localeAsText = locale.toString();
  final Object o = settings.getLocalizedString( localeAsText );
  if ( o == null ) {
    logger.warn( "Unable to translate localized-string property for locale [" + locale + "]. "
      + "The localization does not contain a translation for this locale and does not provide a fallback." );
  }
  return o;
}
 
Example 3
Source File: Concept.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String getName( String locale ) {
  LocalizedString locName = getName();
  if ( locName == null ) {
    return getId();
  }
  String name = locName.getLocalizedString( locale );
  if ( name == null || name.trim().length() == 0 ) {
    return getId();
  }
  return name;
}
 
Example 4
Source File: Concept.java    From pentaho-metadata with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String getDescription( String locale ) {
  LocalizedString locDesc = getDescription();
  if ( locDesc == null ) {
    return getId();
  }
  String name = locDesc.getLocalizedString( locale );
  if ( name == null || name.trim().length() == 0 ) {
    return getId();
  }
  return name;
}
 
Example 5
Source File: MetadataGenerator.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private String extractId(Concept item) {
  LocalizedString localizedName = item.getName();
  Set<String> locales = localizedName.getLocales();
  if (locales.isEmpty()) return "";
  // Just grab the first locale we come across
  // This should normally only one for the star modeler
  //
  String locale = locales.iterator().next();

  String id = localizedName.getLocalizedString(locale);
  id = id.toUpperCase().replace(" ", "_");

  return id;
}
 
Example 6
Source File: ConceptUtil.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static String getDescription(Concept concept, String locale) {
  LocalizedString localizedString = (LocalizedString) concept.getProperty(Concept.DESCRIPTION_PROPERTY);
  if (localizedString==null) return null;
  return localizedString.getLocalizedString(locale);
}
 
Example 7
Source File: ConceptUtil.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static String getName(Concept concept, String locale) {
  LocalizedString localizedString = (LocalizedString) concept.getProperty(Concept.NAME_PROPERTY);
  if (localizedString==null) return null;
  return localizedString.getLocalizedString(locale);
}