Özet - İleri Intl
Intl.NumberFormat, PluralRules ve ListFormat ile bir bildirim metni oluşturucu yazarsın.
Özet - İleri Intl
Bu grupta beş Intl yapıcısını (constructor) öğrendin:
- NumberFormat: sayı ve para birimi biçimlendirir
- PluralRules: çoğul kategorisini verir
- Collator: dile göre sıralar
- ListFormat: listeyi bağlaçlarla birleştirir
- RelativeTimeFormat: görece zaman verir
Hepsi locale dizesi ve options alır. Bildirim metni gibi gerçek görevlerde bunları birlikte kullanırsın: para birimi için NumberFormat, çoğul seçim için PluralRules, liste için ListFormat.
Uygulama Çoğul kategori ve liste
'en' locale'i için bir Intl.PluralRules oluştur. 'en' locale'i için bir Intl.ListFormat oluştur, type 'conjunction' olsun. select(1) sonucunu plural değişkenine, ['Mara', 'Alex'] dizisinin format sonucunu names değişkenine ata.
Örnek çözümü göster
1. new Intl.PluralRules('en').select(1) ile çoğul kategorisini al.
2. new Intl.ListFormat('en', { type: 'conjunction' }).format(['Mara', 'Alex']) ile listeyi biçimle.
3. Sonuçları plural ve names değişkenlerine ata.
Örnek çözüm:
const plural = new Intl.PluralRules('en').select(1);
const names = new Intl.ListFormat('en', { type: 'conjunction' }).format(['Mara', 'Alex']);
Uygulama Bildirim metni oluştur
Bir bildirim metni oluştur. 'en' locale'i için bir Intl.NumberFormat oluştur, style 'currency', currency 'USD' olsun; 49.99 sayısını biçimlendirip amount değişkenine ata. Aynı locale için Intl.ListFormat oluştur, type 'conjunction' olsun; ['book', 'pen'] dizisini biçimlendirip items değişkenine ata.
Örnek çözümü göster
1. new Intl.NumberFormat('en', { style: 'currency', currency: 'USD' }).format(49.99) ile tutarı biçimle.
2. new Intl.ListFormat('en', { type: 'conjunction' }).format(['book', 'pen']) ile listeyi biçimle.
3. Sonuçları amount ve items değişkenlerine ata.
Örnek çözüm:
const amount = new Intl.NumberFormat('en', { style: 'currency', currency: 'USD' }).format(49.99);
const items = new Intl.ListFormat('en', { type: 'conjunction' }).format(['book', 'pen']);
Kendini test et
-
Bir sepetin toplam tutarını para birimiyle göstermek için hangi Intl yapıcısı kullanılır?
- Intl.Collator
- Intl.PluralRules
- Intl.NumberFormat
- Intl.ListFormat
Cevabı göster
Intl.NumberFormat — Doğru. NumberFormat style 'currency' ile para birimi biçimlendirir.
-
Yapıcıları kullanımına eşleştir
- NumberFormat
- Para birimi
- PluralRules
- Çoğul kategori
- ListFormat
- Liste birleştirme
- RelativeTimeFormat
- Görece zaman