Skip to content

Commit f7d48ee

Browse files
Portugalmportuga
authored andcommitted
fix: 🐛 replace missing string with empty string
Notify the user of what string is missing via the console rather than the UI. BREAKING CHANGE: MISSING string will no longer be displayed. Closes: #7063
1 parent 4a63c5e commit f7d48ee

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

packages/core/src/js/services/ui-i18n.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
}
9999
};
100100

101+
function getMissingText(path) {
102+
$log.warn(i18nConstants.MISSING + path);
103+
return '';
104+
}
105+
101106
var service = {
102107

103108
/**
@@ -174,14 +179,13 @@
174179
getSafeText: function (path, lang) {
175180
var language = lang || service.getCurrentLang(),
176181
trans = langCache.get(language),
177-
missing = i18nConstants.MISSING + path,
178182
getter = $parse(path);
179183

180184
if (!trans) {
181-
return missing;
185+
return getMissingText(path);
182186
}
183187

184-
return getter(trans) || missing;
188+
return getter(trans) || getMissingText(path);
185189
},
186190

187191
/**

packages/core/test/i18n/directives.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ describe('i18n Directives', function() {
6060

6161
expect(element.find('p').text()).toBe('Search...');
6262
});
63-
it('should get missing text for missing property', function() {
63+
it('should get empty string for missing property', function() {
6464
element = angular.element('<div ui-i18n="en"><p ui-translate="search.bad.text"></p></div>');
6565
recompile();
6666

67-
expect(element.find('p').text()).toBe('[MISSING]search.bad.text');
67+
expect(element.find('p').text()).toBe('');
6868
});
6969
});
7070

@@ -98,15 +98,15 @@ describe('i18n Directives', function() {
9898

9999
expect(element.find('p').text()).toBe('Search...');
100100
});
101-
it('should get missing text for missing property', function() {
101+
it('should get empty string for missing property', function() {
102102
element = angular.element('<div ui-i18n="en"><p ui-t="search.bad.text"></p></div>');
103103
recompile();
104104

105-
expect(element.find('p').text()).toBe('[MISSING]search.bad.text');
105+
expect(element.find('p').text()).toBe('');
106106

107107
$rootScope.$broadcast('$uiI18n');
108108

109-
expect(element.find('p').text()).toBe('[MISSING]search.bad.text');
109+
expect(element.find('p').text()).toBe('');
110110
});
111111
});
112112

@@ -120,11 +120,11 @@ describe('i18n Directives', function() {
120120

121121
expect(element.find('p').text()).toBe('Search...');
122122
});
123-
it('should get missing text for missing property', function() {
123+
it('should get empty string for missing property', function() {
124124
element = angular.element('<div ui-i18n="en"><p>{{"search.bad.text" | t}}</p></div>');
125125
recompile();
126126

127-
expect(element.find('p').text()).toBe('[MISSING]search.bad.text');
127+
expect(element.find('p').text()).toBe('');
128128
});
129129
});
130130

@@ -144,11 +144,11 @@ describe('i18n Directives', function() {
144144

145145
expect(element.find('p').text()).toBe('Search...');
146146
});
147-
it('should get missing text for missing property', function() {
147+
it('should get empty string for missing property', function() {
148148
element = angular.element('<div ui-i18n="en"><p>{{"search.bad.text" | uiTranslate}}</p></div>');
149149
recompile();
150150

151-
expect(element.find('p').text()).toBe('[MISSING]search.bad.text');
151+
expect(element.find('p').text()).toBe('');
152152
});
153153
});
154154
});

packages/core/test/i18n/i18nService.spec.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
describe('i18nService', function () {
2-
var i18nConstants, i18nService;
2+
var $log, i18nConstants, i18nService;
33

44
beforeEach(function() {
5-
module('ui.grid');
5+
$log = jasmine.createSpyObj('$log', ['warn']);
6+
module('ui.grid', function($provide) {
7+
$provide.value('$log', $log)
8+
});
69
inject(function (_i18nConstants_, _i18nService_) {
710
i18nConstants = _i18nConstants_;
811
i18nService = _i18nService_;
912
});
1013
});
14+
afterEach(function() {
15+
$log.warn.calls.reset();
16+
});
1117

1218
describe('i18n service', function() {
1319
it('should default to English', function() {
@@ -77,30 +83,34 @@ describe('i18nService', function () {
7783
it('should get safe text when text is defined', function() {
7884
expect(i18nService.getSafeText('search.placeholder')).toBe('Search...');
7985
});
80-
it('should get missing text for missing property', function() {
86+
it('should get empty string for missing property', function() {
8187
var badText = 'search.bad.text';
8288

83-
expect(i18nService.getSafeText(badText)).toBe(i18nConstants.MISSING + badText);
89+
expect(i18nService.getSafeText(badText)).toBe('');
90+
expect($log.warn).toHaveBeenCalledWith(i18nConstants.MISSING + badText);
8491
});
8592
it('should get fallback text when language is missing or nonexistent', function() {
8693
expect(i18nService.getSafeText('search.placeholder', 'valerian')).toBe('Search...');
8794
});
88-
it('should get missing text when language is missing or nonexistent and there is no fallback', function() {
95+
it('should get empty string when language is missing or nonexistent and there is no fallback', function() {
8996
var badText = 'bad.text';
9097

91-
expect(i18nService.getSafeText(badText, 'valerian')).toBe(i18nConstants.MISSING + badText);
98+
expect(i18nService.getSafeText(badText, 'valerian')).toBe('');
99+
expect($log.warn).toHaveBeenCalledWith(i18nConstants.MISSING + badText);
92100
});
93-
it('should get missing text when language is missing or nonexistent and the fallback language is the same', function() {
101+
it('should get empty string when language is missing or nonexistent and the fallback language is the same', function() {
94102
var missingProperty = 'search.placeholder';
95103

96104
i18nService.setFallbackLang('valerian');
97-
expect(i18nService.getSafeText(missingProperty, 'valerian')).toBe(i18nConstants.MISSING + missingProperty);
105+
expect(i18nService.getSafeText(missingProperty, 'valerian')).toBe('');
106+
expect($log.warn).toHaveBeenCalledWith(i18nConstants.MISSING + missingProperty);
98107
});
99-
it('should get missing text when language is missing or nonexistent and the fallback language is also missing it', function() {
108+
it('should get empty string when language is missing or nonexistent and the fallback language is also missing it', function() {
100109
var missingProperty = 'search.placeholder';
101110

102111
i18nService.setFallbackLang('orcish');
103-
expect(i18nService.getSafeText(missingProperty, 'valerian')).toBe(i18nConstants.MISSING + missingProperty);
112+
expect(i18nService.getSafeText(missingProperty, 'valerian')).toBe('');
113+
expect($log.warn).toHaveBeenCalledWith(i18nConstants.MISSING + missingProperty);
104114
});
105115
});
106116
});

0 commit comments

Comments
 (0)