blob: dc9bf7f464e3072badba933cd20d5cb3420b6779 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Contracts\Translation;
13
14/**
15 * @author Fabien Potencier <fabien@symfony.com>
16 *
17 * @method string getLocale() Returns the default locale
18 */
19interface TranslatorInterface
20{
21 /**
22 * Translates the given message.
23 *
24 * When a number is provided as a parameter named "%count%", the message is parsed for plural
25 * forms and a translation is chosen according to this number using the following rules:
26 *
27 * Given a message with different plural translations separated by a
28 * pipe (|), this method returns the correct portion of the message based
29 * on the given number, locale and the pluralization rules in the message
30 * itself.
31 *
32 * The message supports two different types of pluralization rules:
33 *
34 * interval: {0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples
35 * indexed: There is one apple|There are %count% apples
36 *
37 * The indexed solution can also contain labels (e.g. one: There is one apple).
38 * This is purely for making the translations more clear - it does not
39 * affect the functionality.
40 *
41 * The two methods can also be mixed:
42 * {0} There are no apples|one: There is one apple|more: There are %count% apples
43 *
44 * An interval can represent a finite set of numbers:
45 * {1,2,3,4}
46 *
47 * An interval can represent numbers between two numbers:
48 * [1, +Inf]
49 * ]-1,2[
50 *
51 * The left delimiter can be [ (inclusive) or ] (exclusive).
52 * The right delimiter can be [ (exclusive) or ] (inclusive).
53 * Beside numbers, you can use -Inf and +Inf for the infinite.
54 *
55 * @see https://en.wikipedia.org/wiki/ISO_31-11
56 *
57 * @param string $id The message id (may also be an object that can be cast to string)
58 * @param array $parameters An array of parameters for the message
59 * @param string|null $domain The domain for the message or null to use the default
60 * @param string|null $locale The locale or null to use the default
61 *
62 * @return string The translated string
63 *
64 * @throws \InvalidArgumentException If the locale contains invalid characters
65 */
66 public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null);
67}