-# Copyright 1999-2016 Gentoo Foundation
+# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Id$
# @ECLASS: l10n.eclass
# @MAINTAINER:
+# Ulrich Müller <ulm@gentoo.org>
+# @AUTHOR:
# Ben de Groot <yngwin@gentoo.org>
# @BLURB: convenience functions to handle localizations
# @DESCRIPTION:
# conveniently handle localizations (translations) offered by packages.
# These are meant to prevent code duplication for such boring tasks as
# determining the cross-section between the user's set LINGUAS and what
-# is offered by the package; and generating the right list of linguas_*
-# USE flags.
+# is offered by the package.
# @ECLASS-VARIABLE: PLOCALES
# @DEFAULT_UNSET
# @DESCRIPTION:
# Variable listing the locales for which localizations are offered by
-# the package. Check profiles/desc/linguas.desc to see if the locales
-# are listed there. Add any missing ones there.
+# the package.
#
# Example: PLOCALES="cy de el_GR en_US pt_BR vi zh_CN"
#
# Example: PLOCALE_BACKUP="en_US"
-# Add linguas useflags
-for u in ${PLOCALES}; do
- IUSE+=" linguas_${u}"
-done
-
# @FUNCTION: l10n_for_each_locale_do
# @USAGE: <function>
# @DESCRIPTION:
# Example: l10n_find_plocales_changes "${S}/src/translations" "${PN}_" '.ts'
l10n_find_plocales_changes() {
[[ $# -ne 3 ]] && die "Exactly 3 arguments are needed!"
- einfo "Looking in ${1} for new locales ..."
+ ebegin "Looking in ${1} for new locales"
pushd "${1}" >/dev/null || die "Cannot access ${1}"
local current= x=
for x in ${2}*${3} ; do
popd >/dev/null
# RHS will be sorted with single spaces so ensure the LHS is too
# before attempting to compare them for equality. See bug #513242.
- if [[ $(tr -s "[:space:]" "\n" <<< "${PLOCALES}" | sort | xargs echo) != ${current%[[:space:]]} ]] ; then
- einfo "There are changes in locales! This ebuild should be updated to:"
- einfo "PLOCALES=\"${current%[[:space:]]}\""
+ # Run them both through the same sorting algorithm so we don't have
+ # to worry about them being the same.
+ if [[ "$(printf '%s\n' ${PLOCALES} | LC_ALL=C sort)" != "$(printf '%s\n' ${current} | LC_ALL=C sort)" ]] ; then
+ eend 1 "There are changes in locales! This ebuild should be updated to:"
+ eerror "PLOCALES=\"${current%[[:space:]]}\""
+ return 1
else
- einfo "Done"
+ eend 0
fi
}
# @FUNCTION: l10n_get_locales
# @USAGE: [disabled]
# @DESCRIPTION:
-# Determine which LINGUAS USE flags the user has enabled that are offered
-# by the package, as listed in PLOCALES, and return them. In case no locales
-# are selected, fall back on PLOCALE_BACKUP. When the disabled argument is
-# given, return the disabled useflags instead of the enabled ones.
+# Determine which LINGUAS the user has enabled that are offered by the
+# package, as listed in PLOCALES, and return them. In case no locales
+# are selected, fall back on PLOCALE_BACKUP. When the disabled argument
+# is given, return the disabled locales instead of the enabled ones.
l10n_get_locales() {
- local disabled_locales enabled_locales loc locs
- for loc in ${PLOCALES}; do
- if use linguas_${loc}; then
- enabled_locales+="${loc} "
- else
- disabled_locales+="${loc} "
- fi
- done
- if [[ ${1} == disabled ]]; then
- locs=${disabled_locales}
+ local loc locs
+ if [[ -z ${LINGUAS+set} ]]; then
+ # enable all if unset
+ locs=${PLOCALES}
else
- locs=${enabled_locales:-$PLOCALE_BACKUP}
+ for loc in ${LINGUAS}; do
+ has ${loc} ${PLOCALES} && locs+="${loc} "
+ done
+ fi
+ [[ -z ${locs} ]] && locs=${PLOCALE_BACKUP}
+ if [[ ${1} == disabled ]]; then
+ local disabled_locs
+ for loc in ${PLOCALES}; do
+ has ${loc} ${locs} || disabled_locs+="${loc} "
+ done
+ locs=${disabled_locs}
fi
printf "%s" "${locs}"
}