Skip to content

Commit b4671f5

Browse files
Ismaestroiramos
authored andcommitted
feat(bowser): add browser detection
1 parent 1809ead commit b4671f5

File tree

11 files changed

+54
-4
lines changed

11 files changed

+54
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ npm run build | Build the app for production
5454
npm run build:library | Build the library
5555
npm run lint | Run the linter (tslint)
5656
npm run ci | Execute linter and tests
57-
npm run translate | Generate all json files with the translations in assets folder and translate all keys remaining
57+
npm run extract | Generate all json files with the translations in assets folder
58+
npm run translate | Translate all keys remaining using Google Translate and using English language as the origin
5859
npm run deploy | Build the app and deploy dist folder to Github pages (angular-cli-ghpages) (fork to do this and remove CNAME file)
5960
npm run bundle-report | Build and run webpack-bundle-analyzer over stats json, really cool :)
6061
npm run release | Create a new release using standard-version
@@ -84,6 +85,7 @@ npm run update | Update the project dependencies with ng update
8485
* Scroll to first invalid input in forms (directive)
8586
* Autocomplete enabled in forms
8687
* Modernizr (browser features detection)
88+
* Browser filter (Bowser) for IE ^^
8789
* Google Tag Manager
8890
* Github pages deploy ready
8991
* Unit tests with Jasmine and Karma including code coverage

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"e2e": "ng e2e",
1313
"lint": "ng lint",
1414
"ci": "npm run lint && npm run test && npm run e2e",
15-
"translate": "ngx-translate-extract --input ./src/app --output ./src/assets/i18n/*.json --sort --format namespaced-json --format-indentation ' ' --marker _ && node ./scripts/translate.js",
15+
"extract": "ngx-translate-extract --input ./src/app --output ./src/assets/i18n/*.json --sort --format namespaced-json --format-indentation ' ' --marker _",
16+
"translate": "node ./scripts/translate.js",
1617
"bundle-report": "ng build --prod --stats-json && webpack-bundle-analyzer dist/stats.json",
1718
"release:minor": "standard-version --release-as minor && git push --follow-tags origin master",
1819
"release:major": "standard-version --release-as major && git push --follow-tags origin master",
@@ -62,6 +63,7 @@
6263
"@types/node": "10.11.4",
6364
"angular-cli-ghpages": "0.5.3",
6465
"axios": "0.18.0",
66+
"bowser": "2.0.0-beta.3",
6567
"codelyzer": "4.5.0",
6668
"coveralls": "3.0.2",
6769
"deepmerge": "2.2.1",

src/app/app.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {MatSnackBar} from '@angular/material';
66
import {_} from '@biesbjerg/ngx-translate-extract/dist/utils/utils';
77
import {AppConfig} from './configs/app.config';
88
import {LocalStorage} from 'ngx-store';
9+
import {isBrowserValid} from './shared/helpers/utils.helper';
910

1011
declare const require;
1112
declare const Modernizr;
@@ -38,7 +39,7 @@ export class AppComponent implements OnInit {
3839
this.title.setTitle('Angular Example App');
3940

4041
this.onEvents();
41-
this.checkBrowserFeatures();
42+
this.checkBrowser();
4243
}
4344

4445
onEvents() {
@@ -63,6 +64,16 @@ export class AppComponent implements OnInit {
6364
});
6465
}
6566

67+
checkBrowser() {
68+
if (isBrowserValid()) {
69+
this.checkBrowserFeatures();
70+
} else {
71+
this.translateService.get([String(_('changeBrowser'))]).subscribe((texts) => {
72+
this.snackBar.open(texts['changeBrowser'], 'OK');
73+
});
74+
}
75+
}
76+
6677
checkBrowserFeatures() {
6778
let supported = true;
6879
for (const feature in Modernizr) {

src/app/shared/helpers/utils.helper.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {animate, AnimationTriggerMetadata, style, transition, trigger} from '@angular/animations';
2+
declare const require;
3+
const bowser = require('bowser');
24

35
export const scrollToElement = (element) => {
46
if (element) {
@@ -28,6 +30,21 @@ export const isPalindrome = (str) => {
2830
return true;
2931
};
3032

33+
export const isBrowserValid = () => {
34+
const browser = bowser.getParser(window.navigator.userAgent);
35+
return browser.satisfies({
36+
windows: {
37+
'internet explorer': '>10',
38+
},
39+
macos: {
40+
safari: '>10.1'
41+
},
42+
chrome: '>20.1.1432',
43+
firefox: '>31',
44+
opera: '>22'
45+
});
46+
};
47+
3148
export const fadeInOut: AnimationTriggerMetadata = trigger('fadeInOut', [
3249
transition(':enter', [
3350
style({opacity: 0}),

src/assets/i18n/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"canVote": "Can vote :)",
88
"cancel": "Cancel",
99
"cannotVote": "Cannot vote anymore :(",
10+
"changeBrowser": "Your browser is not supported. Please use, Chrome, Firefox, Safari, Opera or IE>11",
1011
"create": "Create",
1112
"createHero": "Create a hero",
1213
"createNewHero": "Create new hero",
@@ -50,8 +51,9 @@
5051
"snapshot": "Snapshot",
5152
"sureRemoveHero": "Do you want to remove the hero?",
5253
"topHeroes": "Heroes most liked",
54+
"undefined": "",
5355
"updateBrowser": "You are using an old browser, please update it and reload the page.",
5456
"yeahPalindrome": "That is a palindrome!",
5557
"yellow": "Yellow",
5658
"yes": "Yes"
57-
}
59+
}

src/assets/i18n/es.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"canVote": "Puedes votar :)",
88
"cancel": "Cancelar",
99
"cannotVote": "No puedes votar más :(",
10+
"changeBrowser": "Tu navegador no es compatible. Por favor usa Chrome, Firefox, Safari, Opera or IE>11",
1011
"create": "Crear",
1112
"createHero": "Añadir un heroe",
1213
"createNewHero": "Crear nuevo heroe",
@@ -50,6 +51,7 @@
5051
"snapshot": "Captura",
5152
"sureRemoveHero": "¿Estas seguro de que quieres eliminar el heroe?",
5253
"topHeroes": "Heroes más votados",
54+
"undefined": "",
5355
"updateBrowser": "Estas usando un navegador antiguo, por favor actualiza la versión y recarga la página.",
5456
"yeahPalindrome": "Eso es un palindrome!",
5557
"yellow": "Amarillo",

src/assets/i18n/eu.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"canVote": "Bozkatu dezakezu :)",
88
"cancel": "Ezeztatu",
99
"cannotVote": "Ezin duzu gehiago bozkatu :(",
10+
"changeBrowser": "Zure arakatzailea ez da onartzen. Mesedez erabili Chrome, Firefox, Safari, Opera edo IE>11",
1011
"create": "Sortu",
1112
"createHero": "Heroi bat gehitu",
1213
"createNewHero": "Sortu heroi berri bat",
@@ -50,6 +51,7 @@
5051
"snapshot": "Kaptura",
5152
"sureRemoveHero": "Ziur zaude aukeratutako heroia ezabatu nahi duzula?",
5253
"topHeroes": "Boto gehien daukaten heroiak",
54+
"undefined": "",
5355
"updateBrowser": "Nabigatzaile zaharkitu batekin ari zara lanean, mesedez eguneratu bertsioa eta ondoren birkargatu orrialdea.",
5456
"yeahPalindrome": "Palindromo bat da!",
5557
"yellow": "Horia",

src/assets/i18n/pt-br.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"canVote": "Vote :)",
88
"cancel": "Cancelar",
99
"cannotVote": "Não é mais possível voltar:(",
10+
"changeBrowser": "Seu navegador não é suportado. Por favor use Chrome, Firefox, Safari, Opera o IE>11",
1011
"create": "Criar",
1112
"createHero": "Crie um herói",
1213
"createNewHero": "Criar novo herói",
@@ -50,6 +51,7 @@
5051
"snapshot": "Instantâneo",
5152
"sureRemoveHero": "Você tem certeza que quer remover o herói?",
5253
"topHeroes": "Heróis mais curtidos",
54+
"undefined": "",
5355
"updateBrowser": "Você está usando um navegador antigo, atualize a versão e recarregue a página.",
5456
"yeahPalindrome": "Isso é um palíndromo!",
5557
"yellow": "Amarelo",

src/assets/i18n/zh-cn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"canVote": "可以投票 :)",
88
"cancel": "取消",
99
"cannotVote": "不能再投票了 :(",
10+
"changeBrowser": "您的浏览器不受支持。请使用Chrome,Firefox,Safari,Opera或IE> 11",
1011
"create": "创建",
1112
"createHero": "创建一个英雄",
1213
"createNewHero": "创建一个新英雄",
@@ -50,6 +51,7 @@
5051
"snapshot": "快照",
5152
"sureRemoveHero": "你想要移除一个英雄吗?",
5253
"topHeroes": "最喜欢的英雄",
54+
"undefined": "",
5355
"updateBrowser": "您正在使用一个旧版本浏览器,请更新它并重新加载页面。",
5456
"yeahPalindrome": "那是一个回文!",
5557
"yellow": "黄色",

0 commit comments

Comments
 (0)