question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with WKWebView

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request

Current behavior When using WKWebView with Ionic 2, the translation file is loaded, but the translation tokens are not shown until you do something (like changing of tab which I think triggers change detection). I tried to trigger the change detection manually, but it didn’t work. The onLangChange observable works. Was working fine in UIWebView.

I also that the earlier the package is initialized, the more often the bug happens.

Expected/desired behavior The translation tokens to be replaced by the actual translation strings.

Reproduction of the problem You see the code used here.

Please tell us about your environment:

  • ng2-translate version: 3.1.2
  • Angular version: 2.0.0
  • Browser: iOS 10 WKWebView
  • Language: TypeScript 2.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
biesbjergcommented, Nov 29, 2016

This should be solved now. Uninstall wkwebview and install it again.

1reaction
carlgik4commented, Nov 6, 2017

I google a lot and finally got the ngx-translate to work: First, upgrade cordova and ionic cli to latest version

`xxx:Tabs u$ cordova -v 7.1.0

xxx:Tabs u$ ionic -v 3.16.0

xxx:Tabs u$ ionic info

cli packages: (/Users/xxx/NPM/lib/node_modules)

@ionic/cli-utils  : 1.16.0
ionic (Ionic CLI) : 3.16.0

global packages:

cordova (Cordova CLI) : 7.1.0 

local packages:

@ionic/app-scripts : 3.0.1
Cordova Platforms  : ios 4.5.3
Ionic Framework    : ionic-angular 3.8.0

System:

Android SDK Tools : 25.3.1
ios-deploy        : 1.9.2 
ios-sim           : 6.1.2 
Node              : v6.11.5
npm               : 3.10.10 
OS                : macOS Sierra
Xcode             : Xcode 9.0 Build version 9A235 

Environment Variables:

ANDROID_HOME : /Applications/Android/sdk

Misc:

backend : pro`

create a brand new project

ionic start Tabs sidemenu
cd Tabs
npm install @ngx-translate/core @ngx-translate/http-loader --save

The new project will use wkwebview as default, and there are some error with the usage docs: https://ionicframework.com/docs/developer-resources/ng2-translate/ we should use HttpClientModule instead of HttpModule For the app.module.ts

import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { HttpClientModule, HttpClient } from "@angular/common/http";

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, 'assets/i18n/', '.json');
}

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    }),
    IonicModule.forRoot(MyApp),
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    ...
  ],
  providers: [
    ...
    HttpClient,
    TranslateService,
    ...
  ]
})
export class AppModule {}

For app.component.ts

import { TranslateService } from '@ngx-translate/core';

export class MyApp {
  constructor(public platform: Platform, public splashScreen: SplashScreen,
    translate: TranslateService) {
    translate.setDefaultLang('en');
    let browserLang = translate.getBrowserLang();
    translate.use(browserLang.match(/en|zh/) ? browserLang : 'en');
  }
}

After that, create i18n folder in src/assets create en.json { “HELLO” : “hello” }

For page usage, you can use pipe

{{'HELLO' | translate}}

or manually:

export class HomePage {
  constructor(public navCtrl: NavController,
    private translateService: TranslateService) {
      this.translateService.get('HELLO').subscribe(
        value => {
          // value is our translated string
          let alertTitle = value;
          console.log("translate alert title:" + alertTitle);
        }
      )
  }
}

Hope you save your life with these code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem using a WKWebView to load my site - Apple Developer
Problem using a WKWebView to load my site​​ Hi, i´m trying to use a WKWebView to make an app that could load my...
Read more >
Why Is WKWebView So Heavy and Why Is Leaking It So Bad?
A somewhat common source of bugs is improper management of WKWebView on iOS. The problem is that webviews are incredibly heavy objects from ......
Read more >
Newest 'wkwebview' Questions - Stack Overflow
iOS WKWebView does not load url. I try to open webView, it works fine after first app download. But after several times clicking...
Read more >
Playback problem in WKWebView and iOS 16.1 on iPad with ...
Description I have an iOS app based on a WKWebView, which uses videojs internally to play HLS streams (using MSE, which is available...
Read more >
213510 – iOS 14: ITP causes issues for hybrid (WKWebView ...
Bug 213510 - iOS 14: ITP causes issues for hybrid (WKWebView) apps using cookies for authentication etc. Summary: iOS 14: ITP causes issues...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found