Sorunuzu sorun ve bu sayfaya ve seçtiğiniz AI sağlayıcısına referans vererek belgenin bir özetini alın
Sürüm Geçmişi
- "Geçmiş başlatıldı"v5.5.1029.06.2025
Bu sayfanın içeriği bir yapay zeka kullanılarak çevrildi.
Orijinal içeriğin İngilizce son sürümünü görüntüleyinBu dokümantasyonu geliştirmek için bir fikriniz varsa, lütfen GitHub'da bir çekme isteği göndererek katkıda bulunmaktan çekinmeyin.
Dokümantasyon için GitHub bağlantısıBelge Markdown'ını panoya kopyala
Numaralandırma / Çoğullaştırma
Numaralandırma Nasıl Çalışır
Intlayer'da numaralandırma, enu fonksiyonu aracılığıyla gerçekleştirilir ve belirli anahtarları karşılık gelen içeriklerine eşler. Bu anahtarlar sayısal değerleri, aralıkları veya özel tanımlayıcıları temsil edebilir. React Intlayer veya Next Intlayer ile kullanıldığında, uygun içerik uygulamanın yerel ayarına ve tanımlanan kurallara göre otomatik olarak seçilir.
Numaralandırmayı Ayarlama
Intlayer projenizde numaralandırmayı ayarlamak için, numaralandırma tanımlarını içeren bir içerik modülü oluşturmanız gerekir. İşte araba sayısı için basit bir numaralandırma örneği:
Kodu panoya kopyala
import { enu, type Dictionary } from "intlayer";
const carEnumeration = {
key: "car_count",
content: {
numberOfCar: enu({
"<-1": "Eksi bir arabadan az",
"-1": "Eksi bir araba",
"0": "Araba yok",
"1": "Bir araba",
">5": "Bazı arabalar",
">19": "Çok araba",
"fallback": "Fallback değeri", // İsteğe bağlı
}),
},
} satisfies Dictionary;
export default carEnumeration;
Bu örnekte, enu çeşitli koşulları belirli içeriklere eşler. Bir React bileşeninde kullanıldığında, Intlayer verilen değişkene göre uygun içeriği otomatik olarak seçebilir.
Bildirim sırası Intlayer numaralandırmalarında önemlidir. İlk geçerli bildirim alınacak olanıdır. Birden fazla koşul uygularsa, beklenmedik davranışlardan kaçınmak için doğru sıralandığından emin olun.
Eğer hiçbir fallback bildirilmezse, hiçbir anahtar eşleşmezse fonksiyon undefined döndürür.
React Intlayer ile Numaralandırmayı Kullanma
To use enumeration in a React component, you can leverage the useIntlayer hook from the react-intlayer package. This hook retrieves the correct content based on the specified ID. Here's an example of how to use it:
Kodu panoya kopyala
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const CarComponent: FC = () => {
const { numberOfCar } = useIntlayer("car_count");
return (
<div>
<p>
{
numberOfCar(0) // Output: No cars
}
</p>
<p>
{
numberOfCar(6) // Output: Some cars
}
</p>
<p>
{
numberOfCar(20) // Output: Many cars
}
</p>
<p>
{
numberOfCar(0.01) // Output: Fallback value
}
</p>
</div>
);
};
To use enumeration in Next.js Client Components, retrieve it via the useIntlayer hook. Here's an example:
Kodu panoya kopyala
"use client";
import type { FC } from "react";
import { useIntlayer } from "next-intlayer";
const CarComponent: FC = () => {
const { numberOfCar } = useIntlayer("car_count");
return (
<div>
<p>{numberOfCar(6)}</p>
</div>
);
};
export default CarComponent;
To use enumeration in Vue components, retrieve it via the useIntlayer hook. Here's an example:
Kodu panoya kopyala
To use enumeration in Svelte components, retrieve it via the useIntlayer hook. The store is accessed with $. Here's an example:
Kodu panoya kopyala
To use enumeration in Preact components, retrieve it via the useIntlayer hook. Here's an example:
Kodu panoya kopyala
import type { FC } from "preact";
import { useIntlayer } from "preact-intlayer";
const CarComponent: FC = () => {
const { numberOfCar } = useIntlayer("car_count");
return (
<div>
<p>{numberOfCar(6)}</p>
</div>
);
};
export default CarComponent;
To use enumeration in SolidJS components, retrieve it via the useIntlayer hook. Here's an example:
Kodu panoya kopyala
import type { Component } from "solid-js";
import { useIntlayer } from "solid-intlayer";
const CarComponent: Component = () => {
const { numberOfCar } = useIntlayer("car_count");
return (
<div>
<p>{numberOfCar(6)}</p>
</div>
);
};
export default CarComponent;
To use enumeration in Angular components, retrieve it via the useIntlayer hook. Here's an example:
Kodu panoya kopyala
To use enumeration with vanilla-intlayer, retrieve it via the useIntlayer hook. Here's an example:
Kodu panoya kopyala
import { installIntlayer, useIntlayer } from "vanilla-intlayer";
installIntlayer();
const content = useIntlayer("car_count").onChange((newContent) => {
document.getElementById("cars")!.textContent = newContent.numberOfCar(6);
});
// Initial render
document.getElementById("cars")!.textContent = content.numberOfCar(6);
Ek Kaynaklar
Yapılandırma ve kullanım hakkında daha detaylı bilgi için aşağıdaki kaynaklara başvurun:
Bu kaynaklar, farklı ortamlar ve çeşitli çerçevelerde Intlayer'ın kurulumu ve kullanımı hakkında daha fazla bilgi sağlar.
Using Ordinal Enumeration
To use this in a React component, call the enumeration with the last digit of the number to get the correct suffix, then pass the full count as the insertion value:
Kodu panoya kopyala
import type { FC } from "react";
import { useIntlayer } from "react-intlayer";
const RankingComponent: FC<{ count: number }> = ({ count }) => {
const { ordinal } = useIntlayer("ranking_component");
// Get the last digit to determine the correct suffix
const lastDigit = Math.abs(count) % 10;
return (
<div>
<p>
{
ordinal(lastDigit)({ count }) // e.g., "5th place" for count=5
}
</p>
</div>
);
};
To use this in Next.js Client Components, call the enumeration with the last digit of the number to get the correct suffix, then pass the full count as the insertion value:
Kodu panoya kopyala
"use client";
import type { FC } from "react";
import { useIntlayer } from "next-intlayer";
const RankingComponent: FC<{ count: number }> = ({ count }) => {
const { ordinal } = useIntlayer("ranking_component");
const lastDigit = Math.abs(count) % 10;
return (
<div>
<p>{ordinal(lastDigit)({ count })}</p>
</div>
);
};
export default RankingComponent;
To use this in Vue components, call the enumeration with the last digit of the number to get the correct suffix, then pass the full count as the insertion value:
Kodu panoya kopyala
To use this in Svelte components, call the enumeration with the last digit of the number to get the correct suffix, then pass the full count as the insertion value:
Kodu panoya kopyala
To use this in Preact components, call the enumeration with the last digit of the number to get the correct suffix, then pass the full count as the insertion value:
Kodu panoya kopyala
import type { FC } from "preact";
import { useIntlayer } from "preact-intlayer";
const RankingComponent: FC<{ count: number }> = ({ count }) => {
const { ordinal } = useIntlayer("ranking_component");
const lastDigit = Math.abs(count) % 10;
return (
<div>
<p>{ordinal(lastDigit)({ count })}</p>
</div>
);
};
export default RankingComponent;
To use this in SolidJS components, call the enumeration with the last digit of the number to get the correct suffix, then pass the full count as the insertion value:
Kodu panoya kopyala
import type { Component } from "solid-js";
import { useIntlayer } from "solid-intlayer";
const RankingComponent: Component<{ count: number }> = (props) => {
const { ordinal } = useIntlayer("ranking_component");
return (
<div>
<p>{ordinal(Math.abs(props.count) % 10)({ count: props.count })}</p>
</div>
);
};
export default RankingComponent;
To use this in Angular components, call the enumeration with the last digit of the number to get the correct suffix, then pass the full count as the insertion value:
Kodu panoya kopyala
To use this with vanilla-intlayer, call the enumeration with the last digit of the number to get the correct suffix, then pass the full count as the insertion value:
Kodu panoya kopyala
import { installIntlayer, useIntlayer } from "vanilla-intlayer";
installIntlayer();
const content = useIntlayer("ranking_component");
const lastDigit = Math.abs(5) % 10;
document.getElementById("ranking")!.textContent = content.ordinal(lastDigit)({
count: 5,
});
Additional Resources
For more detailed information on configuration and usage, refer to the following resources:
These resources provide further insights into the setup and usage of Intlayer in different environments and with various frameworks.
