public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Ben de Groot <yngwin@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] RFC: l10n.eclass
Date: Thu, 19 Jul 2012 23:37:32 +0800	[thread overview]
Message-ID: <CAB9SyzTKLe5A3W9Hk==QxMng14oXbFu68qvDuhdP2y-sR-r=+A@mail.gmail.com> (raw)
In-Reply-To: <20120719151422.1fb9883b@sera-17.lan>

[-- Attachment #1: Type: text/plain, Size: 1254 bytes --]

On 19 July 2012 21:14, Ralph Sennhauser <sera@gentoo.org> wrote:
>
> I assume the P in PLOCALS stands for package. Not that obvious if you
> ask me. L10N_LOCALS would at least tell me which eclass this variable
> belongs to.

Yes, as P is widely used to refer to the package. I wanted something to
reflect that these are the locales offered by the package.

> Instead of using LINGUAS you should make use of the use function to get
> your cross sections. ie.
>
> for locale in ${PLOCALES}; do
>   if use linguas_${locale}; then
>     enabled_locales+=" ${locale}"
>   else
>     disabled_locales+=" ${locale}"
>   fi
> done
>
> First, this is guaranteed by PMS and so independent of package manager
> and second, you do not have to care about locales in LINGUAS which are
> invalid for the package. Could be that Portage re-exports a sanitized
> LINGUAS tough, but I doubt it.

This is a good suggestion, as it makes things simpler and more along
expected lines.

I got a few more suggestions on IRC, and I have updated the eclass
accordingly. Please check the attached new version, also available at
https://gitorious.org/gentoo-qt/qt/blobs/master/eclass/l10n.eclass

-- 
Cheers,

Ben | yngwin
Gentoo developer
Gentoo Qt project lead, Gentoo Wiki admin

[-- Attachment #2: l10n.eclass --]
[-- Type: application/octet-stream, Size: 4059 bytes --]

# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: l10n.eclass
# @MAINTAINER:
# Ben de Groot <yngwin@gentoo.org>
# @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="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="en_US"

# Add linguas useflags
if [[ -n "${PLOCALES}" ]]; then
	for u in ${PLOCALES}; do
		IUSE+=" linguas_${u}"
	done
fi

# @FUNCTION: l10n_for_each_locale_do
# @USAGE: <function>
# @DESCRIPTION:
# Convenience function for processing localizations. The parameter should
# be a function (defined in the consuming eclass or ebuild) which takes
# an individual localization as (last) parameter.
#
# Example: l10n_for_each_locale_do install_locale
l10n_for_each_locale_do() {
	local locs x
	locs=$(l10n_get_locales)
	if [[ -n "${locs}" ]]; then
		for x in ${locs}; do
			${@} ${x} || die "failed to process enabled ${x} locale"
		done
	fi
}

# @FUNCTION: l10n_for_each_disabled_locale_do
# @USAGE: <function>
# @DESCRIPTION:
# Complementary to l10n_for_each_locale_do, this function will process
# locales that are disabled. This could be used for example to remove
# locales from a Makefile, to prevent them from being built needlessly.
l10n_for_each_disabled_locale_do() {
	local locs x
	locs=$(l10n_get_locales disabled)
	if [[ -n "${locs}" ]]; then
		for x in ${locs}; do
			${@} ${x} || die "failed to process disabled ${x} locale"
		done
	fi
}

# @FUNCTION: l10n_find_plocales_changes
# @USAGE: <translations dir> <filename pre pattern> <filename post pattern>
# @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= x=
	for x in ${2}*${3} ; do
		x=${x#"${2}"}
		x=${x%"${3}"}
		current+="${x} "
	done
	popd >/dev/null
	if [[ ${PLOCALES} != ${current%[[:space:]]} ]] ; then
		einfo "There are changes in locales! This ebuild should be updated to:"
		einfo "PLOCALES=\"${current%[[:space:]]}\""
	else
		einfo "Done"
	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. This function is normally used internally in this eclass, not by
# l10n.eclass consumers.
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}
	else
		locs=${enabled_locales:-$PLOCALE_BACKUP}
	fi
	printf "%s" "${locs}"
}

  reply	other threads:[~2012-07-19 15:38 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-19  6:45 [gentoo-dev] RFC: l10n.eclass Ben de Groot
2012-07-19 13:14 ` Ralph Sennhauser
2012-07-19 15:37   ` Ben de Groot [this message]
2012-07-20  7:33     ` Ralph Sennhauser
2012-07-23 12:29       ` Ben de Groot
2012-07-23 15:22         ` Ralph Sennhauser
2012-07-19 16:15   ` Ciaran McCreesh
2012-07-19 21:13   ` Zac Medico
2012-07-19 22:34     ` Mike Gilbert
2012-07-20  6:54       ` Ciaran McCreesh
2012-07-20 16:39         ` Mike Gilbert
2012-07-20 17:09           ` Ciaran McCreesh
2012-07-20 17:29             ` Mike Gilbert
2012-07-20 17:35               ` Ciaran McCreesh
2012-07-20 17:43             ` Alexandre Rostovtsev
2012-07-20 17:46               ` Alexandre Rostovtsev
2012-07-20 17:54               ` Ciaran McCreesh
2012-07-20 18:37                 ` Alexandre Rostovtsev
2012-07-20 18:41                   ` Ciaran McCreesh
2012-07-20 19:15                     ` Alexandre Rostovtsev
2012-07-20 19:17                       ` Ciaran McCreesh
2012-07-20 19:48                         ` Alexandre Rostovtsev
2012-07-20 20:02                           ` Ciaran McCreesh
2012-07-20 20:10                             ` Alexandre Rostovtsev
2012-07-20 20:15                               ` Ciaran McCreesh
2012-07-20 20:11                           ` Ian Stakenvicius
2012-07-20 19:05                 ` Ian Stakenvicius
2012-07-20 19:13                   ` Ciaran McCreesh
2012-07-20 20:08                     ` Ian Stakenvicius
2012-07-20 17:44           ` Michał Górny
2012-07-20 18:03             ` Alexandre Rostovtsev
2012-07-20 17:55         ` Mike Gilbert
2012-07-20 18:03           ` Ciaran McCreesh
2012-07-20 18:09             ` Mike Gilbert
2012-07-20 18:15               ` Ciaran McCreesh
2012-07-19 22:44 ` Mike Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAB9SyzTKLe5A3W9Hk==QxMng14oXbFu68qvDuhdP2y-sR-r=+A@mail.gmail.com' \
    --to=yngwin@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox