Skip to content

Commit

Permalink
feat: add lang attribute to Formbricks (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel authored Oct 24, 2024
1 parent 288e50e commit dd8b781
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assets/js/build/survey/survey_deps.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'd18c4036e32153ba476c');
<?php return array('dependencies' => array(), 'version' => 'c59f3ab226aad71e7c11');
2 changes: 1 addition & 1 deletion assets/js/build/survey/survey_deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion assets/js/src/survey_deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import formbricks from "@formbricks/js/app";
* Emit a custom event to let other scripts know that formbricks is loaded.
*/
document.addEventListener("DOMContentLoaded", () => {
window.tsdk_formbricks = formbricks;
window.tsdk_formbricks = {
init: (args) => {
if ( typeof args.attributes === 'object' ) {
args.attributes = {
...window.tsdk_survey_attrs,
...args.attributes
}
}

formbricks?.init(args)
}
};

window.dispatchEvent(new Event("themeisle:survey:loaded"));
});
26 changes: 20 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"semantic-release": "^17.4.7"
},
"dependencies": {
"@formbricks/js": "^2.0.0",
"@formbricks/js": "^2.2.0",
"object-hash": "^3.0.0"
}
}
9 changes: 9 additions & 0 deletions src/Modules/Script_loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ public function load_survey( $handler ) {
$asset_file['version'],
true
);

$language = get_user_locale();
$available_languages = [
'de_DE' => 'de',
'de_DE_formal' => 'de',
];
$lang_code = isset( $available_languages[ $language ] ) ? $available_languages[ $language ] : 'en';

wp_localize_script( $handler, 'tsdk_survey_attrs', [ 'language' => $lang_code ] );
}

/**
Expand Down

0 comments on commit dd8b781

Please sign in to comment.