Skip to content

Commit

Permalink
feat: translate guides/applications/initializers.md (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueCutOfficial authored Feb 16, 2024
1 parent 5aec22c commit 6dec96e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions .remarkignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ guides/**/*.md
!guides/addons-and-dependencies/index.md
!guides/applications/ember-engines.md
!guides/applications/index.md
!guides/applications/initializers.md
!guides/applications/dependency-injection.md
!guides/components/block-content.md
!guides/components/built-in-components.md
Expand Down
39 changes: 19 additions & 20 deletions guides/applications/initializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Les initialiseurs d'instance d'application s'exécutent lorsque l'app a fini de

Les opérations effectuées dans les initialiseurs doivent être aussi légères que possible pour minimiser le délai de chargement de votre app. Bien qu'il existe des techniques avancées pour obtenir des initialiseurs d'application asynchrones (`deferReadiness` et `advanceReadiness`), ces techniques sont généralement à éviter. Toutes les conditions de chargement asynchrone (par exemple l'autorisation de l'utilisateur) sont presque toujours mieux gérées dans les méthodes de route de votre app, qui permettent des interactions avec le DOM en attendant que les conditions soient résolues.

## Application Initializers
## Initialiseurs d'application

Application initializers can be created with Ember CLI's `initializer` generator:
Les initialiseurs d'application peuvent être créés avec le générateur `initializer` d'Ember CLI :

```bash
ember generate initializer shopping-cart
```

Let's customize the `shopping-cart` initializer to inject a `cart` property into all the routes in your application:
Personnalisons l'initialiseur `shopping-cart` (panier, chariot) pour injecter une propriété `cart` dans toutes les routes de l'application :

```javascript {data-filename=app/initializers/shopping-cart.js}
export function initialize(application) {
Expand All @@ -28,34 +28,34 @@ export default {
};
```

## Application Instance Initializers
## Initialiseurs d'instance d'application

Application instance initializers can be created with Ember CLI's `instance-initializer` generator:
Les initialiseurs d'instance d'application peuvent être créés avec le générateur `instance-initializer` d'Ember CLI :

```bash
ember generate instance-initializer logger
```

Let's add some simple logging to indicate that the instance has booted:
Affichons un simple message pour indiquer que l'instance a démarré :

```javascript {data-filename=app/instance-initializers/logger.js}
export function initialize(applicationInstance) {
let logger = applicationInstance.lookup('logger:main');
logger.log('Hello from the instance initializer!');
logger.log('Bonjour de l\'initialiseur d\'instance !');
}

export default {
initialize
};
```

## Specifying Initializer Order
## Spécifier l'ordre d'initialisation

If you'd like to control the order in which initializers run, you can use the `before` and/or `after` options:
Pour contrôler l'ordre dans lequel les initialiseurs s'exécutent, utilisez les options `before` et/ou `after` :

```javascript {data-filename=app/initializers/config-reader.js}
export function initialize(application) {
// ... your code ...
// ... votre code ...
};

export default {
Expand All @@ -66,7 +66,7 @@ export default {

```javascript {data-filename=app/initializers/websocket-init.js}
export function initialize(application) {
// ... your code ...
// ... votre code ...
};

export default {
Expand All @@ -77,7 +77,7 @@ export default {

```javascript {data-filename=app/initializers/asset-init.js}
export function initialize(application) {
// ... your code ...
// ... votre code ...
};

export default {
Expand All @@ -86,28 +86,27 @@ export default {
};
```

Note that ordering only applies to initializers of the same type (i.e. application or application instance).
Application initializers will always run before application instance initializers.
Notez que cet ordre concerne uniquement les initialiseurs de même type (c'est-à-dire d'application ou d'instance d'application). Les initialiseurs d'application s'exécutent toujours avant les initialiseurs d'instance d'application.

## Customizing Initializer Names
## Personnaliser le nom des initialiseurs

By default initializer names are derived from their module name. This initializer will be given the name `logger`:
Par défaut, le nom d'un initialiseur est dérivé du nom de son module. L'initialiseur suivant aura pour nom `logger` :

```javascript {data-filename=app/instance-initializers/logger.js}
export function initialize(applicationInstance) {
let logger = applicationInstance.lookup('logger:main');
logger.log('Hello from the instance initializer!');
logger.log('Bonjour de l\'initialiseur d\'instance !');
}

export default { initialize };
```

If you want to change the name you can simply rename the file, but if needed you can also specify the name explicitly:
Pour changer le nom, vous pouvez simplement renommer le fichier, ou si besoin, spécifier un nom explicitement :

```javascript {data-filename=app/instance-initializers/logger.js}
export function initialize(applicationInstance) {
let logger = applicationInstance.lookup('logger:main');
logger.log('Hello from the instance initializer!');
logger.log('Bonjour de l\'initialiseur d\'instance !');
}

export default {
Expand All @@ -116,4 +115,4 @@ export default {
};
```

This initializer will now have the name `my-logger`.
Cet initialiseur aura maintenant le nom `my-logger`.

0 comments on commit 6dec96e

Please sign in to comment.