Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support additional file formats in ReloadableResourceBundleMessageSource #18990

Closed
spring-projects-issues opened this issue Jun 29, 2016 · 39 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 29, 2016

Loïc Dreux opened SPR-14419 and commented

ReloadableResourceBundleMessageSource could store and load Properties with a custom implementation of the PropertiesPersister like YamlPropertiesPersister.java but the extensions ".properties" and ".xml" are hard coded in Java Source.

A good solution could be to add a property "customExtension" to support other file format like yaml.


Affects: 4.2.6

@spring-projects-issues spring-projects-issues added status: waiting-for-triage An issue we've not yet triaged or decided on type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) and removed type: enhancement A general enhancement labels Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

@62mkv
Copy link

62mkv commented Mar 15, 2019

I would say it's relevant!

@pierrickrouxel
Copy link

I think this is relevant too. All my application is YAML configured (properties, liquibase..) excepted messages. It's really frustrating.
Without this support we must use two different markup language to maintain our projects.

@Gorynych
Copy link

Is it possible to reopen an issue?

@rstoyanchev rstoyanchev reopened this Jan 2, 2020
@rstoyanchev rstoyanchev added for: team-attention type: enhancement A general enhancement and removed status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process labels Jan 2, 2020
@MysteryMS
Copy link

i think it is relevant too

@tonyfarney
Copy link

It's relevant!

@ghahramani
Copy link

any updates on this?

@cristianchies
Copy link

Really waiting for it!!! It's relevant!

@ashutosh049
Copy link

At least tell us when will this be resolved.

@m-a-g-i-c
Copy link

This issue still relevant

@ghost
Copy link

ghost commented Apr 11, 2021

I am here too. Seems relevant to me

@wesleyody
Copy link

Nice issue

@renanfranca
Copy link

I really like this issue! 💕

@5452
Copy link

5452 commented Sep 14, 2021

look forward

@christian-kocke
Copy link

I would really appreciate this feature!

@smunozudp
Copy link

@christian-kocke I found a repo with a work around of this issue, hope it helps.
https://github.com/akkinoc/yaml-resource-bundle

@grzeg
Copy link

grzeg commented Apr 22, 2022

it is relevant for sure!

@viviendehorta
Copy link

yes, it's relevant

@poutsma poutsma modified the milestones: 6.1.0-M1, 6.1.0-M2 May 30, 2023
@Thanthu
Copy link

Thanthu commented Jun 23, 2023

Thanks for your input everyone, we will be addressing this feature request in 6.1.

YES! it took almost 7 years... but we got it 🎉🎉🎉

From which version of Spring Boot is this feature available ? Any resource available with example of its usage would be nice.

@sbrannen
Copy link
Member

From which version of Spring Boot is this feature available ? Any resource available with example of its usage would be nice.

@Thanthu, this issue is still open, which means that the feature has not been released yet.

@sdeleuze sdeleuze assigned sdeleuze and unassigned poutsma Jul 10, 2023
@sdeleuze sdeleuze modified the milestones: 6.1.0-M2, 6.1.0-M3 Jul 10, 2023
@sdeleuze sdeleuze changed the title Support additional file formats in ResourceBundleMessageSource [SPR-14419] Support additional file formats in ResourceBundleMessageSource Jul 10, 2023
@jhoeller jhoeller modified the milestones: 6.1.0-M3, 6.1.0-M4 Jul 17, 2023
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Aug 3, 2023
This commit allows to configure custom file
extensions in ReloadableResourceBundleMessageSource
thanks to a new setFileExtensions setter.

Combined with setPropertiesPersister, it allows
custom implementations supporting any kind of
property file.

Closes spring-projectsgh-18990
@sdeleuze sdeleuze changed the title Support additional file formats in ResourceBundleMessageSource Support additional file formats in ReloadableResourceBundleMessageSource Aug 3, 2023
@sdeleuze sdeleuze changed the title Support additional file formats in ReloadableResourceBundleMessageSource Support additional file formats in ReloadableResourceBundleMessageSource Aug 3, 2023
@sdeleuze
Copy link
Contributor

sdeleuze commented Aug 3, 2023

Thanks everybody for your patience, this issue should be be fixed by this commit.

I was a bit confused initially by the fact that the description of the changes proposed looked irrelevant to ResourceBundleMessageSource, but I understood after digging deeper that it was a typo, and that the change was targeting ReloadableResourceBundleMessageSource which allows to set a custom PropertiesPersister and indeed had .properties and .xml extensions hard coded. The title and description of the issue have been updated accordingly.

In ReloadableResourceBundleMessageSource, it is now possible to customize the file extensions thanks to a new setFileExtensions setter, and combined with setPropertiesPersister, it is possible to implement support for custom file formats.

Since it seems to be a popular use case, I have implemented an example of YAML resource bundle support in https://github.com/sdeleuze/demo-yaml-message-source. The important bits are the YamlPropertiesLoader leveraging org.springframework.beans.factory.config.YamlMapFactoryBean and the declaration of a custom MessageSource bean here:

@Bean
public MessageSource messageSource() {
	ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
	messageSource.setBasename("classpath:messages");
	messageSource.setPropertiesPersister(new YamlPropertiesLoader());
	messageSource.setFileExtensions(List.of(".yml", ".yaml"));
	return messageSource;
}

Spring does not provide such out-of-the box YAML support yet, but hopefully that can serve as an example for the community for how to leverage this feature, and will allow the Spring team to observe how the community leverages those capabilities, which implementations get traction, etc.

@hannah23280
Copy link

this issue has been closed. does that mean Spring framework out of the box finally support yaml format for message source?

@hannah23280
Copy link

hannah23280 commented Sep 4, 2023

if out the box is supported, does spring boot able to autoconfigure to support both yaml and properties, instead of developer having to write codes to configure them.

@sbrannen
Copy link
Member

sbrannen commented Sep 4, 2023

this issue has been closed. does that mean Spring framework out of the box finally support yaml format for message source?

@hannah23280, please read the closing comments for an issue before asking a question.

This was answered in the comment immediately preceding yours.

Spring does not provide such out-of-the box YAML support yet, but hopefully that can serve as an example for the community for how to leverage this feature, and will allow the Spring team to observe how the community leverages those capabilities, which implementations get traction, etc.

@hannah23280
Copy link

Thanks for your input everyone, we will be addressing this feature request in 6.1.

Currently is already 6.1.x, i look through the changes , but could not see anything mentioning this.

@bclozel
Copy link
Member

bclozel commented Feb 20, 2024

@hannah23280 we don't list all changes on this page. This feature has been delivered with milestone 4 as listed on this page and the release notes: https://github.com/spring-projects/spring-framework/releases/tag/v6.1.0-M4

@hannah23280
Copy link

@hannah23280 we don't list all changes on this page. This feature has been delivered with milestone 4 as listed on this page and the release notes: https://github.com/spring-projects/spring-framework/releases/tag/v6.1.0-M4

Thanks! Saw it. That means ReloadableResourceBundleMessageSource can support additional file formats. Hopefully spring boot will autoconfigure it to include yaml , without us developer having to manually do it

@bclozel
Copy link
Member

bclozel commented Feb 20, 2024

@hannah23280 I'm not sure what feature you're expecting in Spring Boot, but there's nothing scheduled at the moment in that area.

@hannah23280
Copy link

hannah23280 commented Feb 20, 2024

@hannah23280 I'm not sure what feature you're expecting in Spring Boot, but there's nothing scheduled at the moment in that area.

Since it is possible for ReloadableResourceBundleMessageSource to support additional file formats, and given the popular usage of yaml, so i thought i'ts might be a matter of time Spring Boot will autoconfigure the ReloadableResourceBundleMessageSource to include yaml as well, so that developers don't have to do it themselves.

@sascha08-15
Copy link

Thanks everybody for your patience, this issue should be be fixed by this commit.

I was a bit confused initially by the fact that the description of the changes proposed looked irrelevant to ResourceBundleMessageSource, but I understood after digging deeper that it was a typo, and that the change was targeting ReloadableResourceBundleMessageSource which allows to set a custom PropertiesPersister and indeed had .properties and .xml extensions hard coded. The title and description of the issue have been updated accordingly.

In ReloadableResourceBundleMessageSource, it is now possible to customize the file extensions thanks to a new setFileExtensions setter, and combined with setPropertiesPersister, it is possible to implement support for custom file formats.

Since it seems to be a popular use case, I have implemented an example of YAML resource bundle support in https://github.com/sdeleuze/demo-yaml-message-source. The important bits are the YamlPropertiesLoader leveraging org.springframework.beans.factory.config.YamlMapFactoryBean and the declaration of a custom MessageSource bean here:

@Bean
public MessageSource messageSource() {
	ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
	messageSource.setBasename("classpath:messages");
	messageSource.setPropertiesPersister(new YamlPropertiesLoader());
	messageSource.setFileExtensions(List.of(".yml", ".yaml"));
	return messageSource;
}

Spring does not provide such out-of-the box YAML support yet, but hopefully that can serve as an example for the community for how to leverage this feature, and will allow the Spring team to observe how the community leverages those capabilities, which implementations get traction, etc.

I tried your implementation and it works IFF one uses the yml with a flat list of attributes. But isn't the entire point of yml vs. properties file to have a more object oriented way to specify i8n texts?

So working with this:

hello.world: hellö
hello:
  world: Hello

Only the first one works with Thymeleaf using <h1 th:text="#{hello.world}"></h1> in the template. The second one, I fail to address - any ideas why that happens and how to work around it?

@Aniokrait
Copy link

Aniokrait commented Mar 7, 2024

@sascha08-15
I had the same issue.
I replaced YamlMapFactoryBean with YamlPropertiesFactoryBean in the load method of YamlPropertiesLoader and it worked.

public class YamlPropertiesLoader implements PropertiesPersister {

	@Override
	public void load(Properties props, InputStream is) {
//		YamlMapFactoryBean yaml = new YamlMapFactoryBean();
                YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
		yaml.setResources(new InputStreamResource(is));
		props.putAll(yaml.getObject());
	}

@sascha08-15
Copy link

sascha08-15 commented Mar 7, 2024

@Aniokrait Thanks for the quick answer! Works like a charm now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests