fosuser+sonatauser ignore french translations - fosuserbundle

I am trying to make a custom labels for a customized register form and login form. I use sonatauserbundle and fosuserbundle, my userbundle hetis from SonataUserbundle.
<?php
namespace SCVBook\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class SCVBookUserBundle extends Bundle
{
/**
* {#inheritdoc}
*/
public function getParent()
{
return 'SonataUserBundle';
}
}
here is my config.file
framework:
#esi: ~
translator: { fallback: fr }
I copied FOSUserBundle.fr.yml to ACME/UserBundle/Resources/translations, but login and register still use the english translation.
here is a line in my login.html.twig
<label for="username"> {{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label>
it makes changes only when I change FOSUserBundle.en.yml in vendor/friendsofsymfony/.../Ressources/translations/FOSUserBundle.en.yml

ok found, just I forgot in app/parameters.yml to set locale to locale:fr, for config.yml
just let it as default.
framework:
#esi: ~
translator: { fallback: "%locale%" }

Related

webview_flutter javascript channel can't communicate in release mode

I am using webview_flutter with version 3.0.0 in my app. I have heavy usage of two-way communication between flutter and javascript. Everything works on debug mode nicely. But, after I build the APK started to get some errors in the javascript channel. I tried with flutter run --release and got the same error.
In my web application (ReactJs), I am using channels in this way:
index.html
<div id="root">
<script>
function sendToFlutter(message) {
if (flutterChannel) {
flutterChannel.postMessage(message);
}
}
</script>
</div>
calling is from React component like this:
window.sendToFlutter("hello-world");
My Webview setup from Flutter end:
Completer<WebViewController> webViewCompleter = Completer<WebViewController>();
WebView(
debuggingEnabled: false,
initialUrl: "https://example.com",
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
webViewCompleter.complete(webViewController);
},
javascriptChannels: <JavascriptChannel>{
JavascriptChannel(
name: "flutterChannel",
onMessageReceived: (JavascriptMessage message) {
if (message.message == "hello-world") {
// Do something
}
})
},
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
return NavigationDecision.prevent;
}
return NavigationDecision.navigate;
},
gestureNavigationEnabled: true,
zoomEnabled: false,
userAgent: Platform.isAndroid ? kAndroidUserAgent : kIosUserAgent,
);
When I call the channel from ReactJs, then I am getting this error:
TypeError: flutterChannel.postMessage is not a function
According to alexbatalov's research in https://github.com/flutter/flutter/issues/92548, the current workaround is to do the following:
Create android/app/proguard-rules.pro. At minimum you need to have a
rule for JavascriptInterface, but I recommend to copy entire
proguard-android.txt, given the fact that you don’t have these rules.
# Preserve annotated Javascript interface methods.
-keepclassmembers class * {
#android.webkit.JavascriptInterface <methods>;
}

How to change the template file(s) for an existing nx schematic

I started to use https://nx.dev/ recently to reorganize an existing monorepo with multiple react frontends and redux state management.
nx provides the ability to create new redux slices out of the box using the #nrwl/react:redux schematic like: nx g #nrwl/react:redux <sliceName>. This is great! However, the template that is being used to create new files does not fit my needs (for example I do not use redux-thunk...) and I would like to use my own template.
I created a new custom schematic with nx g workspace-schematic redux-module and adjusted it to extend #nrwl/react:redux like:
import { chain, externalSchematic, Rule } from '#angular-devkit/schematics';
export default function(schema: any): Rule {
return chain([
externalSchematic('#nrwl/react', 'redux', {
name: schema.name
})
]);
}
Can anyone tell me how to proceed from here to make the custom schematic use my own template files?
Thanks!
You can have the template files inside the directory, load them and then copy to the target destination.e.g.
Dir structure:
Project_root
|- tools
|- schematics
|- your_schematics
|- index.ts
|- templates
|- __name#dasherize__.custom.ts
Content:
/* __name#dasherize__.custom.ts */
export class <%= classify(name) %>Custom {
constructor () {}
}
/* index.ts */
import { chain, externalSchematic, Rule, url, apply, move, mergeWith, MergeStrategy, template, SchematicContext } from '#angular-devkit/schematics';
import { dasherize, classify } from '#angular-devkit/core/src/utils/strings';
import { normalize, strings } from '#angular-devkit/core';
export default function(schema: any): Rule {
const libFileName = dasherize(schema.name);
const projectDirectory = schema.directory
? normalize(schema.directory + '/' + libFileName)
: libFileName;
const projectRoot = normalize('libs/' + projectDirectory);
return chain([
externalSchematic('#nrwl/workspace', 'lib', schema),
addCustomFileToLib(schema, projectRoot)
]);
}
function addCustomFileToLib(schema: any, projectRoot: string): Rule {
const templateFiles = url("./templates");
const newTree = apply(templateFiles, [
move(projectRoot),
template({
...strings,
...schema // pass the objects containing the properties & functions to be used in template file
})
]);
return mergeWith(newTree, MergeStrategy.Default);
}
Note: Name of template file(__name#dasherize__.custom.ts) is an expression which will be compiled/changed according to the name arg passed from cli while executing the schematics.

Ionic 2 File Plugin usage examples

Does anyone have complete examples about how to use the Cordova Native File Plugin in a Ionic 2/Angular 2 project?
I installed this plugin but the documentation don't seems to make much sense to me due the fact it is fragmented and lacks of a complete example, including all needed imports.
For example, the following example don't shows where objects like LocalFileSystem or window came from.
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
console.log('file system open: ' + fs.name);
fs.root.getFile("newPersistentFile.txt", { create: true, exclusive: false }, function (fileEntry) {
console.log("fileEntry is file?" + fileEntry.isFile.toString());
// fileEntry.name == 'someFile.txt'
// fileEntry.fullPath == '/someFile.txt'
writeFile(fileEntry, null);
}, onErrorCreateFile);
}, onErrorLoadFs);
For example, I need to crate a property file. First I need to check if a file exists on app sandbox storage area, if don't exists I must create it. Then I must open the file write data and save it . How could I do that?
Ionic 2 comes with a Cordova file plugin wrapper:
http://ionicframework.com/docs/v2/native/file/.
The necessary file system paths (e.g. cordova.file.applicationDirectory) you can find here at the documentation of the original plugin:
https://github.com/apache/cordova-plugin-file#where-to-store-files. Note that not all platforms support the same storage paths.
I even managed to build a file browser with it. Use it like so:
import {Component} from '#angular/core';
import {File} from 'ionic-native';
...
File.listDir(cordova.file.applicationDirectory, 'mySubFolder/mySubSubFolder').then(
(files) => {
// do something
}
).catch(
(err) => {
// do something
}
);
Here is an example using IonicNative for an app I am working on where I want
to send an email with a csv file attachment.
import {EmailComposer} from '#ionic-native/email-composer';
import {File} from '#ionic-native/file';
class MyComponent {
constructor(private emailComposer: EmailComposer, private file: File) {
}
testEmail() {
this.file.writeFile(this.file.dataDirectory, 'test.csv', 'hello,world,', {replace: true})
.then(() => {
let email = {
to: 'email#email',
attachments: [
this.file.dataDirectory + 'test.csv'
],
subject: 'subject',
body: 'body text...',
isHtml: true
};
this.emailComposer.open(email);
})
.catch((err) => {
console.error(err);
});
}
}
This was tested with ionic 3.7.0 on IOS.

Dynamically Change Page <Head> In Angular2

In AngularJS 1 we simply add ng-app at top of the HTML tag and bind services to change metadata on the fly.
But in Angular2 the quickstart app in official site made index.html completely static (css, meta, ...), only left app tag to bind with bootstrap()
Now how we can do when we want to build many panel with different style and js plugins, meta keyword...
update
There is now also the Meta service that allows to modify meta tags
https://angular.io/docs/ts/latest/api/platform-browser/index/Meta-class.html
original
There is currently no support built in in Angular. There is an open issue though for (almost) full support of meta tags and other stuff in <head>.
Currently there is only built-in support for the <title> tag using the Title service.
constructor(private title:Title) {
}
updateTitle(title:string) {
this.title.setTitle(title);
console.log(this.title.getTitle());
}
I have just released #ngx-meta/core plugin, using that you can add meta information inside the data property of routes:
const routes = [
{
path : 'home',
component : HomeComponent,
data : {
meta : {
title : 'Sweet home',
description : 'Home, home sweet home... and what?',
}
}
},
{
path : 'duck',
component : DuckComponent,
data : {
meta : {
title : 'Rubber duckie',
description : 'Have you seen my rubber duckie?',
}
}
},
{
path : 'toothpaste',
component : ToothpasteComponent,
data : {
meta : {
title : 'Toothpaste',
override : true, // prevents appending/prepending the application name to the title attribute
description : 'Eating toothpaste is considered to be too healthy!',
}
}
}
...
];
If you want to override values supplied at the route configuration, it's possible to set meta information programmatically - just in the component class:
...
import { Component, OnInit } from '#angular/core';
import { MetaService } from '#ngx-meta/core';
...
#Component({
...
})
export class ItemComponent implements OnInit {
...
constructor(private metaService: MetaService) { }
...
ngOnInit() {
this.item = //HTTP GET for "item" in the repository
this.metaService.setTitle(`Page for ${this.item.name}`);
this.metaService.setTag('og:image', this.product.imageUrl);
}
}
You can find detailed instructions at #ngx-meta/core github repository. Also, source files might be helpful to introduce a custom logic.

play framework route that matches all

I'm working on an angular app using play framework for my rest-services. Everything in the public folder is an angular app (stylesheets, javascripts, images and html). I want every request that is not for something in the stylesheets, javascripts, templates or images folder to be routed to the index.html page. This is so that angular routing can take over from there...
As a side note i can mention that I am going to place every restservice under /services/ which links to my own java controllers.
Is it possible in play framework 2.3.4 to define a route that catches all without having to use the matching elements?
This is my route defs so far:
GET / controllers.Assets.at(path="/public", file="index.html")
GET /stylesheets/*file controllers.Assets.at(path="/public/stylesheets", file)
GET /javascripts/*file controllers.Assets.at(path="/public/javascripts", file)
GET /templates/*file controllers.Assets.at(path="/public/templates", file)
GET /images/*file controllers.Assets.at(path="/public/images", file)
#this line fails
GET /* controllers.Assets.at(path="/public", file="index.html")
It's not possible to omit usage of matching elements but you can route a client via controller. The route definition looks like this:
GET /*path controllers.Application.matchAll(path)
And the corresponding controller can be implemented as follows:
public class Application extends Controller {
public static Result matchAll(String path) {
return redirect(controllers.routes.Assets.at("index.html"));
}
}
Update
If you don't want to redirect a client you can return a static resource as a stream. In this case a response MIME type is required.
public class Application extends Controller {
public static Result matchAll(String path) {
return ok(Application.class.getResourceAsStream("/public/index.html")).as("text/html");
}
}
For this task you can use onHandlerNotFound in Global class which will render some page without redirect:
import play.*;
import play.mvc.*;
import play.mvc.Http.*;
import play.libs.F.*;
import static play.mvc.Results.*;
public class Global extends GlobalSettings {
public Promise<Result> onHandlerNotFound(RequestHeader request) {
return Promise.<Result>pure(notFound(
views.html.notFoundPage.render(request.uri())
));
}
}
Answer for scala developers using playframework :)
Similar to above one about creating controller which will accept parameters and then omit them.
Example routing:
GET / controllers.Assets.at(path="/public", file="index.html")
GET /*ignoredPath ui.controller.AssetsWithIgnoredWildcard.at(path="/public", file="index.html", ignoredPath: String)
controller with assets injected by framework:
class AssetsWithIgnoredWildcard #Inject() (assets: Assets) {
def at(
path: String,
file: String,
wildcardValueToIgnore: String,
aggressiveCaching: Boolean = false): Action[AnyContent] = {
assets.at(path, file, aggressiveCaching)
}
}

Resources