How to set the language to use for AngularDart Material components? - angular-material

By default, date picker, and form validation messages are in english.
I need to have them in french.
I can't find any documentation... :'(

Angular Material documentation states:
By default, the MAT_DATE_LOCALE injection token will use the existing LOCALE_ID locale code from #angular/core. If you want to override it, you can provide a new value for the MAT_DATE_LOCALE token:
#NgModule({
providers: [
{provide: MAT_DATE_LOCALE, useValue: 'fr-FR'},
],
})
export class MyApp {}
It's also possible to set the locale at runtime using the setLocale method of the DateAdapter.
Another option may be found at https://angular.io/api/core/LOCALE_ID.

package:intl is used which you can see documentation here: https://pub.dev/packages/intl
The translations itself aren't bundled. They would need to be sent to a translation service itself.

Related

Use plugin config as paramater in services.yml

The documentation only shows that you can pass the SystemConfigService as a parameter to another service.
Is there also the possibility to pass directly the value from the plugin configuration?
Background of the question: I would like to initialize directly an instance of an external component. But this expects fixed arguments as strings. Alternatively, one would otherwise have to write some kind of factory.
Hm, it's possible to do. I have not done this directly myself, but 99% confident that it will work. You may need to play around with it a little.
In the services.xml you can use symfony expressions.
<argument type="expression">service('Shopware\Core\System\SystemConfig\SystemConfigService').get('SwagBasicExample.config.example')</argument>
You may need to find the alias name for the Shopware\Core\System\SystemConfig\SystemConfigService class instead. Also check the Symfony documentation, you can do a lot more with this!
I myself passed an array as an argument, but used a custom class as a config getter like so:
<argument type="expression">
{
"shop_is_active": service('config_bridge').get('isActive'),
"customer_number": service('config_bridge').get('customerNumber'),
"shop_number": service('config_bridge').get('shopNumber'),
"apikey": service('config_bridge').get('apiKey')
}
</argument>
Not strictly necessary as Shopware already requires it, but always a good practice to add the requirement to your plugin composer file:
"require": {
...,
"symfony/expression-language": "~5.3.0|~5.4.0"
},
As of today it's not possible to inject specific system_config values in services.

How to use dependency injection in service based Angular2 project

The problem
For the past week I've been working on a authentication library for an Angular2 project. This library is mostly service based and should work almost directly out of the box. The only thing you need to do is include it in your app and set the config object for it.
The main service here is the AuthService. This service includes both the Http and another custom service. The thing is that both these dependencies require the developer to point out the providers for these classes. I'm not sure If I've got this right, but I've seen solutions where they need to import HTTP_PROVIDERS in order to use Http.
So if I import the AuthService as a dependency, I still need to import both the HTTP_PROVIDERS and custom service to make the DI work.
bootstrap(App, [AuthService, HTTP_PROVIDERS, CustomService]);
This messes up my idea of the module being easy to include. I'd like to only supply the import AuthService.
Thing I tried so far
First of all I started out reading some of the blogs about DI in Angular2. As most of you may know Thoughtram is doing a great job on supplying this information (also EggHead.io). I ended up reading these two posts:
http://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html
http://blog.thoughtram.io/angular/2015/09/17/resolve-service-dependencies-in-angular-2.html
After reading them I thought the solution was simple, but after a while this seemed not the case. I guess I'm missing the point here. Also working Spring boot where DI is the main selling point, it seemed odd that I did not manage to get it working (might be the fact that Angular2 is still in Alpha and documentation is scarce).
Solutions I tried
So I tried some solution I came up with, but none of them worked.
Providing a constant
My first thought was to look at the HTTP_PROVIDERS constant that was like a provider for the Http dependency. I ended up looking at the source code for it.
https://github.com/angular/angular/blob/b0009f03d510370d9782cf76197f95bb40d16c6a/modules/angular2/http.ts#L151
After that I thought that I'd best try to implement this for my own class.
export const AUTH_PROVIDERS: any[] = [
provide(AuthService, {
useFactory: (http, customService) => new AuthService(http, customService),
deps: [Http, CustomService]
})
,
provide(CustomService, {
useFactory: () => new CustomService(),
})
];
Once completed I included it in my bootstrap function, after which I was greeted with another error.
Token must be defined!
I took some time trying to find the problem, but I did not manage to do so.
Using an annotation
One of the new things in Angular2 is annotations. So I hoped one of these would be able to help me out with my problem. The #Component and #View seemed not the ones I needed. I believe they focus more on visual aspects of an object that functional (as the View is not something I need, but is mandatory).
The next part can seem odd as I could not find if this was an annotation or not (probably not...). I tried giving #Provider a shot. That resulted in the following "possible" solution.
#Provider({
token: 'AuthService',
useFactory: (http, customService) => new AuthService(http, customService)
...
})
export class AuthService{
constructor(http: Http, customService, CustomService){...}
}
This just gave me another error, but this time it was thrown by the Typescript compiler.
error TS2348: Value of type 'typeof Provider' is not callable. Did you mean to include 'new'?
Anyways can someone please help me with this. Is one of the solutions above a step in the right direction or am I doing something horribly wrong?
Thanks in advance.
Well, I found the problem, but it's something I hadn't thought of before (probably cause I work mainly with Java). One of the things Typescript (and eventually JavaScript) does not like is referencing a Class that's defined below the piece of code where you need it. I guess that's where the 'Token must be defined!' error comes from. Anyways switching the code pieces solved the problem.
export class AuthService{...implementation...}
export const AUTH_PROVIDERS : any[] = [
HTTP_PROVIDERS,
provide(AuthService, {
useFactory: (http, customService) => new AuthService(http, customService),
deps: [Http, CustomService]
}),
provide(CustomService, {
useFactory: () => new CustomService()
})
];
Hope this may help others in the future.

Orchard Contrib.DateTimeField missing style and script

`I've installed the DateTime Field module to Orchard and assigned two fields to my custom part, but when navigating to the Admin Edit page for the custom type implimenting the custom part, I recieve an error like this:
A 'stylesheet' named 'jQueryUtils_TimePicker' could not be found.
When looking in the Contrib.DateTime.cshtml View, I find that the following two resources are required, but I can't find them in the jQuery module's resource manifest.
Style: jQueryUtils_TimePicker
Script: jQueryUtils_TimePicker
Where are these meant to be defined and stored?
Thanks in advance.
P.S.
If I change both to jQueryUI_TimePicker (for which there is a script and style defined in the jquery module resource manifest), then it doesn't throws an error, but the time picker doesn't work.
Contrib.DateTimeField is obsolete since 1.4 so you shouldn't use it.
The DateTimeField has been integrated in Orchard.Fields has a core feature.

Render a partial from a task in Symfony 1.4

I'm trying to render a partial in a Symfony task and having no luck. I found docs in 1.1 that say to just call get_partial() but apparently that's no longer readily available in 1.4. I tried loading the helper manually with sfLoader::getHelpers('Partial'); but I get "Class sfLoader not found". Any help would be greatly appreciated.
For reference what I'm trying to do is generate an HTML file called 'header.html' from my global header partial used in all of my layouts for inclusion in a third-party forum I'm integrating (Simple Machines/SMF).
First load:
sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
then just call:
get_partial()
Don't forget to add an application name in your task's options. Look for this line:
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED,'The application name', 'frontend')
Now $this->configuration returns the sfApplicationConfiguration that you need.
This will do the trick:
//load the Partial helper to be able to use get_partial()
$contextInstance = sfContext::createInstance($this->configuration);
$contextInstance->getConfiguration()->loadHelpers('Partial');
sfLoader was deprecated in symfony 1.2 - I think you need to look over the 1.4 API and the upgrade help from whichever version you're familiar with, as these are going to be resources you'll need to refer to a lot.
The trick to solving your problem is to load the helper with the loadHelpers() method provided by the sfApplicationConfiguration class - your task should hook this method in its configure() method. I've not done it before myself, mind...
Just called a partial in a task for use in sending free trial nag email here's the code:
//combines the partial with passed variables and puts the results in a string variable
$contextInstance = sfContext::createInstance($this->configuration);
$contextInstance->getConfiguration()->loadHelpers('Partial');
$partial_in_a_string = $contextInstance->getController()
->getAction('module_name', 'action_name')
->getPartial('module_name/partial_name', array('var_name'=>'var_value'));
you can access the current configuration with
$this->configuration
You can also define application command option in taskClass::configure() method (if you have used the symfony generate:task to generate the task class you should have frontend as default application option).
Optionally you can pass an application using --application=appName from cli when calling your task.
Be sure to have the application option in your configure method:
protected function configure()
{
$this->addOptions(array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'frontend')
))
....
And then, in the execute method:
protected function execute($arguments = array(), $options = array())
{
sfContext::createInstance($this->configuration)->getConfiguration()->loadHelpers('Partial');
On this way you will prevent these errors:
The "default" context does not exist.
and
Argument 1 passed to sfContext::createInstance() must be an instance
of sfApplicationConfiguration

how to get locale information on a GWT application

In GWT I have to specify what locales are supported in my application. The code get compiled in various files, one for each locale (beside other versions), but I have to give my clients one only URL. This URL is supposed to be a page that should be displayed according to the locale preferred by the browser.
I dont't want to have an HTTP parameter for the locale since I want to forse the locale preferred by the browser.
How can this be coded in GWT?
Should I try to to this using apache rewrite rules? I thied it, but I think I cannot access such parameter easely in a rewrite rule.
Thanks a lot,
Giuseppe
I had the same problem as you, but as I really need to know the current locale (I'm requesting a second server for data that I want to be localizable) I found this class:
com.google.gwt.i18n.client.LocaleInfo#getCurrentLocale(). That should give you what GWT uses currently.
GWT has good support for internationalization. See this link. The i18nCreator command can help you to set up the internationalization infrastructure for similar to the way projectCreator and applicationCreator set up the GWT application.
If you have static strings (i.e. Invalid Entry!) that need to be internationalized, you don't need any additional flag to i18nCreator command to create the properties files and infrastructure.
If you have strings that need to accept parameters (i.e. Hello {0}), you need to pass the -createMessages flag to i18nCreator command to create the properties files and infrastructure.
Now your module needs to include the i18n module in your MyApplication.gwt.xml:
<inherits name="com.google.gwt.i18n.I18N"/>
Define a Java interface in the same package as your property files that extends Constants or Messages and defines methods (name matches the property entries) that all return string.
MyConstants.properties contains:
errorMessage=Invalid Entry!
MyConstants.java contains:
import com.google.gwt.i18n.client.Constants;
public interface myConstants extends Constants {
String errorMessage();
}
Now to access these internationalized Strings from you application:
public class MyApplication implements EntryPoint {
private static final MyConstants constants = (MyConstants)GWT.create(MyConstants.class);
public void onModuleLoad() {
final Label errorMessage = new Label(constants.errorMessage);
}
}
GWT implements the interface for you automagically.
You can get messages in a similar way.
Hopefully this can help you get started.
Unless I am reading the documentation incorrectly I don't think you have to do anything.
GWT and Locale
By making locale a client property, the standard startup process in gwt.js chooses the appropriate localized version of an application, providing ease of use (it's easier than it might sound!), optimized performance, and minimum script size.
The way I read it, as long as your module has added all the locale choices to it, it should be automatic?
Check this com.google.gwt.i18n.client.LocaleInfo.getCurrentLocale()
<inherits name="com.google.gwt.i18n.I18N"/>
<!-- Use browser-specified locale for i18n -->
<set-configuration-property name="locale.useragent" value="Y"/>
<!-- Specify locales your application support -->
<extend-property name="locale" values="en"/>
<extend-property name="locale" values="de_DE"/>
<extend-property name="locale" values="ru_RU"/>

Resources