# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

DESCRIPTION="Japanese ja_JP locale data for musl libc"
HOMEPAGE="https://github.com/tai-ga/musl-locale-ja_JP"
SRC_URI="https://github.com/tai-ga/musl-locale-ja_JP/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"

# Upstream declares no license. The catalog msgids derive from musl (MIT)
# and the Adélie musl-locales templates (LGPL-3/MIT); see metadata.xml.
LICENSE="LGPL-3 MIT"
SLOT="0"
KEYWORDS="~amd64"
IUSE=""

RDEPEND="!sys-libs/glibc"
BDEPEND="sys-devel/gettext"

S="${WORKDIR}/musl-locale-ja_JP-${PV}"

src_compile() {
	msgfmt -o ja_JP.UTF-8 "${S}/musl-po/ja_JP.po" || die "failed to compile ja_JP locale data"
	# Sanity check: musl parses locale files as gettext MO objects.
	[[ "$(od -An -tx1 -N4 ja_JP.UTF-8 2>/dev/null | tr -d ' \n')" == "de120495" ]] \
		|| die "compiled ja_JP.UTF-8 does not look like an MO file"
}

src_install() {
	insinto /usr/share/i18n/locales/musl
	doins ja_JP.UTF-8
	newenvd - "00musl-locale-ja_JP" <<-EOF
	MUSL_LOCPATH="/usr/share/i18n/locales/musl"
	EOF
}

pkg_postinst() {
	elog "Run 'source /etc/profile' (or re-login) then set, e.g.:"
	elog "  LANG=ja_JP.UTF-8"
	elog "  LC_ALL=ja_JP.UTF-8"
	elog "Verify with: locale && date +'%A %B' && cal"
}