Skip to content

Commit dd40804

Browse files
authored
Allow adding and removing resource Ids from a Localization. (#197)
* Allow adding and removing resource Ids from a Localization. * Rename onLanguageChange to onChange
1 parent f4438bd commit dd40804

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

fluent-dom/src/dom_localization.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export default class DOMLocalization extends Localization {
4545
};
4646
}
4747

48-
onLanguageChange() {
49-
super.onLanguageChange();
48+
onChange() {
49+
super.onChange();
5050
this.translateRoots();
5151
}
5252

fluent-dom/src/localization.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ export default class Localization {
2424
new CachedAsyncIterable(this.generateMessages(this.resourceIds));
2525
}
2626

27+
addResourceIds(resourceIds) {
28+
this.resourceIds.push(...resourceIds);
29+
this.onChange();
30+
}
31+
32+
removeResourceIds(resourceIds) {
33+
this.resourceIds = this.resourceIds.filter(r => !resourceIds.includes(r));
34+
this.onChange();
35+
}
36+
2737
/**
2838
* Format translations and handle fallback if needed.
2939
*
@@ -134,14 +144,14 @@ export default class Localization {
134144
}
135145

136146
handleEvent() {
137-
this.onLanguageChange();
147+
this.onChange();
138148
}
139149

140150
/**
141151
* This method should be called when there's a reason to believe
142152
* that language negotiation or available resources changed.
143153
*/
144-
onLanguageChange() {
154+
onChange() {
145155
this.ctxs =
146156
new CachedAsyncIterable(this.generateMessages(this.resourceIds));
147157
}

0 commit comments

Comments
 (0)