I am currently attempting to manage the language settings of my Angular application within WordPress using WordPress Polylang.
To achieve this, I have set up the following structure in my Angular application:
getLanguage.php
<?php
require_once("../../../../../wp-load.php");
$data = get_bloginfo("language");
echo json_encode($data);
?>
http.service.ts
getLanguage(): any {
return this.http.get(environment.url)
}
app.component.ts
this.http.getLanguage().subscribe( res => {
console.log(res);
this.lang = res;
});
The response will be either de-DE or fr-FR.
This setup is functioning correctly. However, I have encountered an issue where changing the language on my WordPress site to French does not reflect in the Angular application, and the LanguageCode remains at the default value of the German language, de-DE.
My Angular application resides within the WordPress theme and is accessed via a WordPress page-app.php.
I am curious if there is an alternative method to transmit the language setting from WordPress Polylang to the Angular app, or if there may be something overlooked in my current setup.