Currently, I am developing a hybrid app that focuses on localization. The concept involves providing the user with three language options to choose from. To accomplish this, I have set up a node.js server on Bluemix that interacts with a Cloudant NoSQL database. My approach includes comparing the "rev" values in my local JSON file with those on the server. If there is a discrepancy, I need to update the local file accordingly. While I have managed to retrieve the necessary data, I am facing challenges when it comes to writing this data back to the local file. My development environment consists of Cordova and Ionic 2.
public GetRevFromNode(SelectedLanguage,JsonDataLocal)
{
JsonDataLocal.subscribe(val=>{ this.LocJson=val; })
this.http.get('https://*********/retriev?ID=\"'+SelectedLanguage+"\"").subscribe( result=>
{
if(this.LocJson['_rev']==result.json().value)
{
console.log("The Local JSON is Updated to the latest");
return ;
}
{
console.log("Updating JSON File for "+SelectedLanguage+".json .......");
var ob=this.file.readAsText(this.file.applicationDirectory+'www/assets/i18n',"ar.json");
ob.then(function(val){
console.log("ar JSON = "+val);
});
this.file.createFile('file:///android_asset/www',"ess.json",true).catch(val=>{
console.log("Can't create because = "+JSON.stringify(val));
});
this.file.writeFile('file:///android_asset/www/',"index.html","\"value\":\"Please\"",{replace:true , append:false} ).catch(val=>{
console.log("Can't write because ="+JSON.stringify(val));
console.log("Updating Done ...")
}
} );
}
I attempted to resolve the issue by using this.file.appDirectory but encountered errors. Additionally, I tried making implicit adjustments as demonstrated here.
An error message is displayed:
Uncaught promise [object Object]
Using stringify: {Code:1000}
I can read and check for the existence of files normally; however, creating and writing pose challenges.