@@ -44,31 +44,207 @@ Please refer to the config file for an overview of the available options.
44
44
Documentation
45
45
------------
46
46
47
- Once installed the package provides global helper functions to use as shown below.
47
+ Once installed the package provides the following global helper functions:
48
+
49
+ ### Country Name
50
+
51
+ Returns the country name given its two-letter/five-letter code;
48
52
49
53
``` blade
50
54
country name: {{ country_name($country, $locale) }}
51
55
```
52
56
53
57
``` php
54
- $content = view($templatePath, ['country' => 'FR', 'locale' => 'NL'])->render();
55
- echo $content, PHP_EOL; // country name: Frankrijk
56
- ```
57
-
58
- The following helper functions exist and use the same parameters as the ones from the parent package.
59
-
60
- - ` country_name ` : returns the country name given its two-letter/five-letter code;
61
- - ` currency_name ` : returns the currency name given its three-letter code;
62
- - ` currency_symbol ` : returns the currency symbol given its three-letter code;
63
- - ` language_name ` : returns the language name given its two-letter/five-letter code;
64
- - ` locale_name ` : returns the language name given its two-letter/five-letter code;
65
- - ` timezone_name ` : returns the timezone name given its identifier;
66
- - ` country_timezones ` : returns the timezone identifiers of the given country code;
67
- - ` format_currency ` : formats a number as a currency;
68
- - ` format_number ` : formats a number;
69
- - ` format_datetime ` : formats a date time;
70
- - ` format_date ` : formats a date;
71
- - ` format_time ` : formats a time;
58
+ echo view($templatePath, ['country' => 'FR', 'locale' => 'NL'])->render();
59
+ // country name: Frankrijk
60
+ ```
61
+
62
+ ### Currency Name
63
+
64
+ Returns the currency name given its three-letter code;
65
+
66
+ ``` blade
67
+ currency name: {{ currency_name($currency, $locale) }}
68
+ ```
69
+
70
+ ``` php
71
+ echo view($templatePath, ['currency' => 'JPY', 'locale' => 'PT'])->render();
72
+ // currency name: Iene japonês
73
+ ```
74
+
75
+ ### Currency Symbol
76
+
77
+ Returns the currency symbol given its three-letter code;
78
+
79
+ ``` blade
80
+ currency symbol: {{ currency_symbol($currency, $locale) }}
81
+ ```
82
+
83
+ ``` php
84
+ echo view($templatePath, ['currency' => 'JPY', 'locale' => 'PT'])->render();
85
+ // currency symbol: JP¥
86
+ ```
87
+
88
+ ### Language name
89
+
90
+ Returns the currency symbol given its three-letter code;
91
+
92
+ ``` blade
93
+ language name: {{ language_name($language, $locale) }}
94
+ ```
95
+
96
+ ``` php
97
+ echo view($templatePath, ['language' => 'it', 'locale' => 'nl'])->render();
98
+ // language name: Italiaans
99
+ ```
100
+
101
+ ### Locale name
102
+
103
+ Returns the currency symbol given its three-letter code;
104
+
105
+ ``` blade
106
+ locale name: {{ locale_name($data, $locale) }}
107
+ ```
108
+
109
+ ``` php
110
+ echo view($templatePath, ['data' => 'sw', 'locale' => 'nl'])->render();
111
+ // locale name: Swahili
112
+ ```
113
+
114
+ ### Timezone name
115
+
116
+ Returns the timezone name given its identifier;
117
+
118
+ ``` blade
119
+ timezone name: {{ locale_name($data, $locale) }}
120
+ ```
121
+
122
+ ``` php
123
+ echo view($templatePath, ['timezone' => 'Asia/Tokyo', 'locale' => 'es'])->render();
124
+ // timezone name: hora de Japón (Tokio)
125
+ ```
126
+
127
+ ### Country Timezones
128
+
129
+ Returns the timezone identifiers of the given country code;
130
+
131
+ ``` blade
132
+ country timezones: {{ implde(", ", country_timezones($country)) }}
133
+ ```
134
+
135
+ ``` php
136
+ $content = view($templatePath, ['country' => 'CD', 'locale' => 'es'])->render();
137
+ echo $content, PHP_EOL; // country timezones: Africa/Kinshasa, Africa/Lubumbashi
138
+ ```
139
+
140
+ ### Format Currency
141
+
142
+ Formats a number as a currency;
143
+
144
+ ``` blade
145
+ format currency: {{ format_currency($amount, $currency, $attrs, $locale) }}
146
+ ```
147
+
148
+ ``` php
149
+ $templateData = [
150
+ 'amount' => 100.356,
151
+ 'currency' => 'USD',
152
+ 'locale' => 'ES',
153
+ 'attrs' => [
154
+ 'fraction_digit' => 1,
155
+ 'rounding_mode' => 'floor',
156
+ ]
157
+ ];
158
+ echo view($templatePath, $templateData)->render();
159
+ // format currency: 100,3 US$
160
+ ```
161
+
162
+ ### Format Number
163
+
164
+ Formats a number;
165
+
166
+ ``` blade
167
+ format number: {{ format_number($number, $attrs, $locale) }}
168
+ ```
169
+
170
+ ``` php
171
+ $templateData = [
172
+ 'number' => 100.356,
173
+ 'locale' => 'nl',
174
+ 'style' => 'spellout',
175
+ 'type' => 'double',
176
+ 'attrs' => [
177
+ 'fraction_digit' => 1,
178
+ 'rounding_mode' => 'floor',
179
+ ]
180
+ ];
181
+ echo view($templatePath, $templateData)->render();
182
+ // format number: honderd komma drie
183
+ ```
184
+
185
+ ### Format DateTime
186
+
187
+ Formats a date and time;
188
+
189
+ ``` blade
190
+ format datetime: {{ format_datetime($date, $dateFormat, $timeFormat, $pattern, $timezone, $calendar, $locale) }}
191
+ ```
192
+
193
+ ``` php
194
+ $templateData = [
195
+ 'date' => 'yesterday',
196
+ 'dateFormat' => 'full',
197
+ 'timeFormat' => 'full',
198
+ 'pattern' => '' ,
199
+ 'timezone' => 'Africa/Lubumbashi',
200
+ 'calendar' => 'gregorian' ,
201
+ 'locale' => 'sw',
202
+ ];
203
+ echo view($templatePath, $templateData)->render();
204
+ // format datetime: Alhamisi, 2 Juni 2022 00:00:00 Saa za Afrika ya Kati
205
+ ```
206
+
207
+ ### Format Date
208
+
209
+ Formats a the date portion of a datetime;
210
+
211
+ ``` blade
212
+ format date: {{ format_date($date, $dateFormat, $pattern, $timezone, $calendar, $locale) }}
213
+ ```
214
+
215
+ ``` php
216
+ $templateData = [
217
+ 'date' => 'yesterday',
218
+ 'dateFormat' => 'long',
219
+ 'pattern' => '' ,
220
+ 'timezone' => 'Africa/Lubumbashi',
221
+ 'calendar' => 'gregorian' ,
222
+ 'locale' => 'sw',
223
+ ];
224
+ echo view($templatePath, $templateData)->render();
225
+ // format date: 2 Juni 2022
226
+ ```
227
+
228
+ ### Format Time
229
+
230
+ Formats the time portion of a datetime;
231
+
232
+ ``` blade
233
+ format time: {{ format_time($date, $timeFormat, $pattern, $timezone, $calendar, $locale) }}
234
+ ```
235
+
236
+ ``` php
237
+ $templateData = [
238
+ 'date' => 'yesterday',
239
+ 'dateFormat' => 'full',
240
+ 'pattern' => '' ,
241
+ 'timezone' => 'Africa/Lubumbashi',
242
+ 'calendar' => 'gregorian' ,
243
+ 'locale' => 'sw',
244
+ ];
245
+ echo view($templatePath, $templateData)->render();
246
+ // format time: 00:00:00 Saa za Afrika ya Kati
247
+ ```
72
248
73
249
Each function uses the same arguments in the same order as the Twig Extra package filters/functions.
74
250
0 commit comments