-
Notifications
You must be signed in to change notification settings - Fork 894
/
i18n.js
48 lines (44 loc) · 1.4 KB
/
i18n.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { setLocaleData } from "@wordpress/i18n";
import get from "lodash/get";
/**
* Sets the l10n for the given textdomain in Jed.
*
* All the locale data should be available in the l10nNamespace.
*
* @param {string} textdomain The textdomain to set the locale data for.
* @param {string} [l10nNamespace] The global namespace to get the localization
* data from.
*
* @returns {void}
*/
export function setTextdomainL10n( textdomain, l10nNamespace = "wpseoYoastJSL10n" ) {
const translations = get( window, [ l10nNamespace, textdomain, "locale_data", textdomain ], false );
if ( translations === false ) {
// Jed needs to have meta information in the object keyed by an empty string.
setLocaleData( { "": {} }, textdomain );
} else {
setLocaleData( translations, textdomain );
}
}
/**
* Configures the i18n for yoast-components.
*
* We call translation functions using `@wordpress/i18n` so we need to register
* all our strings there too. This function does that.
*
* @returns {void}
*/
export function setYoastComponentsL10n() {
setTextdomainL10n( "yoast-components" );
}
/**
* Configures the l10n for wordpress-seo-js.
*
* We call translation functions using `@wordpress/i18n` so we need to register
* all our strings there too. This function does that.
*
* @returns {void}
*/
export function setWordPressSeoL10n() {
setTextdomainL10n( "wordpress-seo" );
}