File translation-update.spec of Package translation-update

#
# spec file for package translation-update
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           translation-update
BuildRequires:  fdupes
BuildRequires:  gettext
Version:        15.2
Release:        0
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# Translation updates. Files here should not conflict with
# translation-update-from-translation-update-upstream.
# In case of conflict, the particular translation file is lost.
Source:         translation-update.tar.bz2
Source1:        README
Source2:        COPYING
Source3:        AUTHORS
# WARNING: Before submitting new version, always review "osc diff", fix bad
# language description and update Obsoletes for removed locales.
# Auto-generated by translation-update-upstream supplementary scripts
# upstream-collect.sh + translation-update-upstream-to-translation-update.sh
# (Includes packages that don't correctly update with
# translation-update-upstream and packages that are not rebuilt in
# target project.)
Source4:        translation-update-from-translation-update-upstream-20200601.tar.bz2
# Last minute additions that take precedence over
# translation-update-from-translation-update-upstream. Strings are
# merged in a smart way and existing strings are not lost.
Source5:        translation-update2.tar.bz2
Source6:        translation-update.rpmlintrc
# Supplementary scripts:
# Reset ranslation-update.tar.bz2.
Source100:      reset-translation-update.sh
# Strip all sub-packages from the spec file.
Source101:      translation-update-spec-reset-lang-list.sh
# Generate spec file with needed sub-packages from .build.log from "osc build".
Source102:      translation-update-spec-generate-lang-list.sh
BuildArch:      noarch
Summary:        Translation Updates
License:        GPL-2.0+
Group:          System/Base
# Existed up to SLE 15
Obsoletes:      translation-update-as
# Existed up to SLE 15
Obsoletes:      translation-update-be-latin
# Existed up to SLE 15
Obsoletes:      translation-update-bn_IN
# Existed up to 13.1, but not obsoleted up to Leap 42.1
Obsoletes:      translation-update-ca@valencia
# Existed up to 2014, but not obsoleted up to Leap 42.1
Obsoletes:      translation-update-caValencia
# Existed up to SLE 15
Obsoletes:      translation-update-dz
# Existed up to SLE 15
Obsoletes:      translation-update-en-shaw
# Existed up to SLE 15
Obsoletes:      translation-update-en_CA
# Existed up to SLE 15
Obsoletes:      translation-update-ga
# Existed up to 12.3, but not obsoleted up to Leap 42.1
Obsoletes:      translation-update-ka
# Existed up to SLE 15
Obsoletes:      translation-update-mai
# Existed up to SLE 15
Obsoletes:      translation-update-mk
# Existed up to SLE 15
Obsoletes:      translation-update-nds
# Existed up to SLE 15
Obsoletes:      translation-update-or
# Existed up to SLE 15
Obsoletes:      translation-update-sq
# Existed up to SLE 15
Obsoletes:      translation-update-sr-ije
# Existed up to 13.1, but not obsoleted up to Leap 42.1
Obsoletes:      translation-update-sr@latin
# Existed up to 2014, but not obsoleted up to Leap 42.1
Obsoletes:      translation-update-srLatin
# Existed up to SLE 15
Obsoletes:      translation-update-te
# Existed up to SLE 15
Obsoletes:      translation-update-ug
# Existed up to SLE 15
Obsoletes:      translation-update-zh_HK
# And all these existed up to SLE15 SP1
Obsoletes:      translation-update-ar
Obsoletes:      translation-update-ast
Obsoletes:      translation-update-be
Obsoletes:      translation-update-bg
Obsoletes:      translation-update-bn
Obsoletes:      translation-update-ca
Obsoletes:      translation-update-ca-valencia
Obsoletes:      translation-update-cs
Obsoletes:      translation-update-da
Obsoletes:      translation-update-de
Obsoletes:      translation-update-el
Obsoletes:      translation-update-en
Obsoletes:      translation-update-en_GB
Obsoletes:      translation-update-en_US
Obsoletes:      translation-update-eo
Obsoletes:      translation-update-es
Obsoletes:      translation-update-es_AR
Obsoletes:      translation-update-es_CL
Obsoletes:      translation-update-es_CO
Obsoletes:      translation-update-es_CR
Obsoletes:      translation-update-es_DO
Obsoletes:      translation-update-es_EC
Obsoletes:      translation-update-es_ES
Obsoletes:      translation-update-es_GT
Obsoletes:      translation-update-es_HN
Obsoletes:      translation-update-es_MX
Obsoletes:      translation-update-es_NI
Obsoletes:      translation-update-es_PA
Obsoletes:      translation-update-es_PE
Obsoletes:      translation-update-es_PR
Obsoletes:      translation-update-es_SV
Obsoletes:      translation-update-es_UY
Obsoletes:      translation-update-es_VE
Obsoletes:      translation-update-et
Obsoletes:      translation-update-eu
Obsoletes:      translation-update-fa
Obsoletes:      translation-update-fi
Obsoletes:      translation-update-fr
Obsoletes:      translation-update-fr_CA
Obsoletes:      translation-update-gl
Obsoletes:      translation-update-gu
Obsoletes:      translation-update-he
Obsoletes:      translation-update-hi
Obsoletes:      translation-update-hr
Obsoletes:      translation-update-hu
Obsoletes:      translation-update-ia
Obsoletes:      translation-update-id
Obsoletes:      translation-update-is
Obsoletes:      translation-update-it
Obsoletes:      translation-update-it_IT
Obsoletes:      translation-update-ja
Obsoletes:      translation-update-kk
Obsoletes:      translation-update-km
Obsoletes:      translation-update-kn
Obsoletes:      translation-update-ko
Obsoletes:      translation-update-lt
Obsoletes:      translation-update-lv
Obsoletes:      translation-update-ml
Obsoletes:      translation-update-mr
Obsoletes:      translation-update-nb
Obsoletes:      translation-update-nb_NO
Obsoletes:      translation-update-ne
Obsoletes:      translation-update-nl
Obsoletes:      translation-update-nn
Obsoletes:      translation-update-pa
Obsoletes:      translation-update-pl
Obsoletes:      translation-update-pt
Obsoletes:      translation-update-pt_BR
Obsoletes:      translation-update-pt_PT
Obsoletes:      translation-update-ro
Obsoletes:      translation-update-ru
Obsoletes:      translation-update-sk
Obsoletes:      translation-update-sl
Obsoletes:      translation-update-sr
Obsoletes:      translation-update-sr-latin
Obsoletes:      translation-update-sv
Obsoletes:      translation-update-ta
Obsoletes:      translation-update-th
Obsoletes:      translation-update-tr
Obsoletes:      translation-update-tr_TR
Obsoletes:      translation-update-uk
Obsoletes:      translation-update-vi
Obsoletes:      translation-update-wa
Obsoletes:      translation-update-zh_CN
Obsoletes:      translation-update-zh_TW

%description
This is a set of translation updates that are installed into the
preferred directory, /usr/share/locale-langpack/<locale>/LC_MESSAGES/.

Applications that use gettext correctly can then pick up overridden or
updated translations from this location.

%prep
%setup -n translation-update -a 4
# # These were updated on SLE10 SP1 resp. separately as yast2-trans-{??,??_??}
# rm -fr yast-trans/{ar,bn,ca,cs,de,es,fi,fr,hi,hu,it,ja,ko,nb,nl,pl,pt_BR,ru,sk,ta,zh_CN,zh_TW}
cd ..
mkdir tu2
cd tu2
tar xvf %{S:5}
cd ..

%build
# Merge last minute updates in upstream collected files
shopt -s nullglob
up_dir=../../../translation-update/translation-update
cd ../tu2/translation-update
for PACKAGE in * ; do
  cd $PACKAGE
  for LL in * ; do
    msgfmt --check -o /dev/null $LL/$LL.po || continue
    # ls $up_dir
    up_ll_dir=$up_dir/$PACKAGE/$LL
    up_ll_file=$up_ll_dir/$LL.po
    if [ -f $up_ll_file ]; then
      msgcat --use-first -o tmp.po $LL/$LL.po $up_ll_file \
        && mv tmp.po $up_ll_file \
        || :
    else
      mkdir -p $up_ll_dir
      cp $LL/$LL.po $up_ll_dir
    fi
  done
  cd ..
done

%install
mkdir -p $RPM_BUILD_ROOT%{_datadir}/locale-langpack
# First process translation-update tarball.
shopt -s nullglob
for PACKAGE in * ; do
    if test "$PACKAGE" = translation-update ; then
	continue
    fi
    cd $PACKAGE
    for LNG in * ; do
	cd $LNG
	for PO in *.po ; do
	    if [ ${PO%.po} == $LNG ] ; then
		msgfmt -c -o $PACKAGE.mo $PO
	    else
		msgfmt -c -o ${PO%.$LNG.po}.mo $PO
	    fi
	    if [ -d ${RPM_BUILD_ROOT}%{_datadir}/locale-langpack/$LNG ] ; then
		install -m 644 *.mo ${RPM_BUILD_ROOT}%{_datadir}/locale-langpack/$LNG/LC_MESSAGES
	    else
		install -d ${RPM_BUILD_ROOT}%{_datadir}/locale-langpack/$LNG/LC_MESSAGES
		install -m 644 *.mo ${RPM_BUILD_ROOT}%{_datadir}/locale-langpack/$LNG/LC_MESSAGES
	    fi
	done
	cd ..
    done
    cd ..
done
cd translation-update
# Second process translation-update-from-translation-update-upstream tarball.
# In case of conflict, it will overwrite the previous. (It should contain LCN + upstream fixes together.
for PACKAGE in * ; do
    cd $PACKAGE
    for LNG in * ; do
	cd $LNG
	for PO in *.po ; do

	    # Supplementary scripts make several checks. But if the
	    # downstream po file was already invalid, then update may
	    # still be invalid. Don't fail and ignore such updates.

	    if [ ${PO%.po} == $LNG ] ; then
		if ! msgfmt -c -o $PACKAGE.mo $PO ; then
		    echo "ERROR: $PACKAGE/$LNG/$PO is invalid. Ignoring update."
		    continue
		fi
	    else
		if ! msgfmt -c -o ${PO%.$LNG.po}.mo $PO ; then
		    echo "ERROR: $PACKAGE/$LNG/$PO is invalid. Ignoring update."
		    continue
		fi
	    fi
	    if [ -d ${RPM_BUILD_ROOT}%{_datadir}/locale-langpack/$LNG ] ; then
		install -m 644 *.mo ${RPM_BUILD_ROOT}%{_datadir}/locale-langpack/$LNG/LC_MESSAGES
	    else
		install -d ${RPM_BUILD_ROOT}%{_datadir}/locale-langpack/$LNG/LC_MESSAGES
		install -m 644 *.mo ${RPM_BUILD_ROOT}%{_datadir}/locale-langpack/$LNG/LC_MESSAGES
	    fi
	done
	cd ..
    done
    cd ..
done
cd ..
install -d ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}
install -m 644 %{S:1} ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}
install -m 644 %{S:2} ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}
install -m 644 %{S:3} ${RPM_BUILD_ROOT}%{_defaultdocdir}/%{name}
# For empty subpackages
install -m 644 %{S:2} .

#
# go through valid locales and fail in invalid ones
#
set +x
cd $RPM_BUILD_ROOT%{_datadir}/locale-langpack
for LOCALE in * ; do
	if ! test -d /usr/share/locale/$LOCALE ; then
               echo -n "removing unsupported translation $LOCALE"
               rm -rfv $LOCALE
        fi
done

# FIXME: There are duplicates! Some packages changed its domain and translation-update.tar.bz2 still uses the old one.
%fdupes ${RPM_BUILD_ROOT}

%clean
rm -rf "$RPM_BUILD_ROOT"

%files
%defattr(-,root,root)
%{_defaultdocdir}/%{name}

%changelog
openSUSE Build Service is sponsored by