public interface IFieldUpdateCultureProvider
Example:
Shows how to specify a culture which parses date/time formatting for each field.public void defineDateTimeFormatting() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.insertField(FieldType.FIELD_TIME, true); doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE); // Set a provider that returns a culture object specific to each field. doc.getFieldOptions().setFieldUpdateCultureProvider(new FieldUpdateCultureProvider()); FieldTime fieldDate = (FieldTime) doc.getRange().getFields().get(0); if (fieldDate.getLocaleId() != (int) EditingLanguage.RUSSIAN) fieldDate.setLocaleId((int) EditingLanguage.RUSSIAN); doc.save(getArtifactsDir() + "FieldOptions.UpdateDateTimeFormatting.pdf"); } /// <summary> /// Provides a CultureInfo object that should be used during the update of a particular field. /// </summary> private static class FieldUpdateCultureProvider implements IFieldUpdateCultureProvider { /// <summary> /// Returns a CultureInfo object to be used during the field's update. /// </summary> public CultureInfo getCulture(String name, Field field) { switch (name) { case "ru-RU": CultureInfo culture = new CultureInfo(new Locale(name)); DateTimeFormatInfo format = culture.getDateTimeFormat(); format.setMonthNames(new String[]{"месяц 1", "месяц 2", "месяц 3", "месяц 4", "месяц 5", "месяц 6", "месяц 7", "месяц 8", "месяц 9", "месяц 10", "месяц 11", "месяц 12", ""}); format.setMonthGenitiveNames(format.getMonthNames()); format.setAbbreviatedMonthNames(new String[]{"мес 1", "мес 2", "мес 3", "мес 4", "мес 5", "мес 6", "мес 7", "мес 8", "мес 9", "мес 10", "мес 11", "мес 12", ""}); format.setAbbreviatedMonthGenitiveNames(format.getAbbreviatedMonthNames()); format.setDayNames(new String[]{"день недели 7", "день недели 1", "день недели 2", "день недели 3", "день недели 4", "день недели 5", "день недели 6"}); format.setAbbreviatedDayNames(new String[]{"день 7", "день 1", "день 2", "день 3", "день 4", "день 5", "день 6"}); format.setShortestDayNames(new String[]{"д7", "д1", "д2", "д3", "д4", "д5", "д6"}); format.setAMDesignator("До полудня"); format.setPMDesignator("После полудня"); final String PATTERN = "yyyy MM (MMMM) dd (dddd) hh:mm:ss tt"; format.setLongDatePattern(PATTERN); format.setLongTimePattern(PATTERN); format.setShortDatePattern(PATTERN); format.setShortTimePattern(PATTERN); return culture; case "en-US": return new CultureInfo(new Locale(name)); default: return null; } } }
Method Summary | ||
---|---|---|
abstract com.aspose.words.net.System.Globalization.CultureInfo | getCulture(java.lang.String culture, Field field) | |
Returns a |
public abstract com.aspose.words.net.System.Globalization.CultureInfo getCulture(java.lang.String culture, Field field)
culture
- The name of the culture requested for the field being updated.field
- The field being updated.Example:
Shows how to specify a culture which parses date/time formatting for each field.public void defineDateTimeFormatting() throws Exception { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.insertField(FieldType.FIELD_TIME, true); doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE); // Set a provider that returns a culture object specific to each field. doc.getFieldOptions().setFieldUpdateCultureProvider(new FieldUpdateCultureProvider()); FieldTime fieldDate = (FieldTime) doc.getRange().getFields().get(0); if (fieldDate.getLocaleId() != (int) EditingLanguage.RUSSIAN) fieldDate.setLocaleId((int) EditingLanguage.RUSSIAN); doc.save(getArtifactsDir() + "FieldOptions.UpdateDateTimeFormatting.pdf"); } /// <summary> /// Provides a CultureInfo object that should be used during the update of a particular field. /// </summary> private static class FieldUpdateCultureProvider implements IFieldUpdateCultureProvider { /// <summary> /// Returns a CultureInfo object to be used during the field's update. /// </summary> public CultureInfo getCulture(String name, Field field) { switch (name) { case "ru-RU": CultureInfo culture = new CultureInfo(new Locale(name)); DateTimeFormatInfo format = culture.getDateTimeFormat(); format.setMonthNames(new String[]{"месяц 1", "месяц 2", "месяц 3", "месяц 4", "месяц 5", "месяц 6", "месяц 7", "месяц 8", "месяц 9", "месяц 10", "месяц 11", "месяц 12", ""}); format.setMonthGenitiveNames(format.getMonthNames()); format.setAbbreviatedMonthNames(new String[]{"мес 1", "мес 2", "мес 3", "мес 4", "мес 5", "мес 6", "мес 7", "мес 8", "мес 9", "мес 10", "мес 11", "мес 12", ""}); format.setAbbreviatedMonthGenitiveNames(format.getAbbreviatedMonthNames()); format.setDayNames(new String[]{"день недели 7", "день недели 1", "день недели 2", "день недели 3", "день недели 4", "день недели 5", "день недели 6"}); format.setAbbreviatedDayNames(new String[]{"день 7", "день 1", "день 2", "день 3", "день 4", "день 5", "день 6"}); format.setShortestDayNames(new String[]{"д7", "д1", "д2", "д3", "д4", "д5", "д6"}); format.setAMDesignator("До полудня"); format.setPMDesignator("После полудня"); final String PATTERN = "yyyy MM (MMMM) dd (dddd) hh:mm:ss tt"; format.setLongDatePattern(PATTERN); format.setLongTimePattern(PATTERN); format.setShortDatePattern(PATTERN); format.setShortTimePattern(PATTERN); return culture; case "en-US": return new CultureInfo(new Locale(name)); default: return null; } } }