From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.77) (envelope-from ) id 1Sq1YJ-0006O5-RX for garchives@archives.gentoo.org; Sat, 14 Jul 2012 12:34:28 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CEB35E04E7; Sat, 14 Jul 2012 12:34:05 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 92531E02F0 for ; Sat, 14 Jul 2012 12:34:05 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D7EE51B4018 for ; Sat, 14 Jul 2012 12:34:04 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 9A697E5433 for ; Sat, 14 Jul 2012 12:34:03 +0000 (UTC) From: "Ben de Groot" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ben de Groot" Message-ID: <1342269218.061214eccc7ecbddf9ffcd657ec7117b920df537.yngwin@gentoo> Subject: [gentoo-commits] proj/qt:master commit in: eclass/ X-VCS-Repository: proj/qt X-VCS-Files: eclass/l10n.eclass X-VCS-Directories: eclass/ X-VCS-Committer: yngwin X-VCS-Committer-Name: Ben de Groot X-VCS-Revision: 061214eccc7ecbddf9ffcd657ec7117b920df537 X-VCS-Branch: master Date: Sat, 14 Jul 2012 12:34:03 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: f5e83401-d669-4407-a5c7-3a32b4e8c99a X-Archives-Hash: 814a86505f9fa3b9a6559a6685248dff commit: 061214eccc7ecbddf9ffcd657ec7117b920df537 Author: Ben de Groot gmail com> AuthorDate: Sat Jul 14 12:33:38 2012 +0000 Commit: Ben de Groot gentoo org> CommitDate: Sat Jul 14 12:33:38 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/qt.git;a=3Dco= mmit;h=3D061214ec l10n.eclass: commit first draft for review and testing --- eclass/l10n.eclass | 124 ++++++++++++++++++++++++++++++++++++++++++++++= ++++++ 1 files changed, 124 insertions(+), 0 deletions(-) diff --git a/eclass/l10n.eclass b/eclass/l10n.eclass new file mode 100644 index 0000000..7c9c5b1 --- /dev/null +++ b/eclass/l10n.eclass @@ -0,0 +1,124 @@ +# Copyright 1999-2012 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +# @ECLASS: l10n.eclass +# @MAINTAINER: +# Ben de Groot +# @BLURB: convenience functions to handle localizations +# @DESCRIPTION: +# The l10n (localization) eclass offers a number of functions to more +# 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. + +# @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. +# +# Example: PLOCALES=3D"cy de el_GR en_US pt_BR vi zh_CN" + +# @ECLASS-VARIABLE: PLOCALE_BACKUP +# @DEFAULT_UNSET +# @DESCRIPTION: +# In some cases the package fails when none of the offered PLOCALES are +# selected by the user. In that case this variable should be set to a +# default locale (usually 'en' or 'en_US') as backup. +# +# Example: PLOCALE_BACKUP=3D"en_US" + +# @FUNCTION: l10n_iuse +# @DESCRIPTION: +# Print a list of linguas useflags, corresponding to PLOCALES. +# Normally used within IUSE. +# +# Example: IUSE=3D"doc pdf $(l10n_iuse)" +l10n_iuse() { + [[ -n "${PLOCALES}" ]] && printf 'linguas_%s ' ${PLOCALES} +} + +# @FUNCTION: l10n_for_each_locale_do +# @USAGE: +# @DESCRIPTION: +# Convenience function for processing localizations. The parameter shoul= d +# be a function (defined in the consuming eclass or ebuild) which takes +# an individual localization as parameter. +# +# Example: l10n_for_each_locale_do install_locale +l10n_for_each_locale_do() { + l10n_get_linguas_crosssection + if [[ -n "${L10N_LOCS}" ]]; then + local x + for x in ${L10N_LOCS}; do + ${1} ${x} || die "failed to process ${x} locale" + done + fi +} + +# @FUNCTION: l10n_for_each_unselected_locale_do +# @USAGE: +# @DESCRIPTION: +# Complementary to l10n_for_each_locale_do, this function will process +# locales that are not selected. This could be used for example to remov= e +# locales from a Makefile, to prevent them from being built needlessly. +l10n_for_each_unselected_locale_do() { + local o=3D x=3D + o=3D$(join -v 1 <(echo "${PLOCALES// /$'\n'}") <(echo "${LINGUAS// /$'\= n'}") ) + o=3D${o//$'\n'/' '} + einfo "Unselected locales are: ${o}" + if [[ -n "${o}" ]]; then + for x in ${o}; do + ${1} ${x} || die "failed to process unselected ${x} locale" + done + fi +} + +# @FUNCTION: l10n_find_plocales_changes +# @USAGE: +# @DESCRIPTION: +# Ebuild maintenance helper function to find changes in package offered +# locales when doing a version bump. This could be added for example to +# src_prepare +# +# 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 ..." + pushd "${1}" >/dev/null || die "Cannot access ${1}" + local current=3D x=3D + for x in ${2}*${3} ; do + x=3D${x#"${2}"} + x=3D${x%"${3}"} + current+=3D"${x} " + done + popd >/dev/null + if [[ ${PLOCALES} !=3D ${current%[[:space:]]} ]] ; then + einfo "There are changes in locales! This ebuild should be updated to:= " + einfo "PLOCALES=3D\"${current%[[:space:]]}\"" + fi +} + +# @FUNCTION: l10n_get_linguas_crosssection +# @DESCRIPTION: +# Determine the cross-section of user-set LINGUAS and the locales which +# the package offers (listed in PLOCALES), and export L10N_LOCS. In case +# no locales are selected, fall back on PLOCALE_BACKUP. This function is +# normally used internally in this eclass, not by l10n.eclass consumers. +l10n_get_linguas_crosssection() { + # @VARIABLE: L10N_LOCS + # @DESCRIPTION: Selected locales (cross-section of LINGUAS and PLOCALES= ) + unset L10N_LOCS + local lang=3D loc=3D xloc=3D + for lang in ${LINGUAS}; do + for loc in ${PLOCALES}; do + [[ ${lang} =3D=3D ${loc} ]] && xloc+=3D"${loc} " + done + done + export L10N_LOCS=3D"${xloc:-$PLOCALE_BACKUP}" + einfo "Selected locales are: ${L10N_LOCS}" +}