#!/bin/sh
# Build f-r-n tar after manually cloning f-r-n and editing I18n
#
#
VER="11.0.0"
RELDATE="2009-05-11"
cd work
#
#  release-notes
#
git clone git://git.fedorahosted.org/git/docs/release-notes.git
pushd release-notes
# Now make the place where we will build the tar
TARG="../../tars/fedora-release-notes-${VER}"
mkdir $TARG
cp Makefile $TARG
#  merge in translation repository
git merge --no-commit origin/f11-tx
TFXLAN=(as    bn_IN ca    cs    da    de    el    es    fi    fr    gu    he    hi    hr    hu    id    it    ja    kn    ko    ml    mr    ms    nb    nl    or    pa    pl    pt_BR pt    ru    sk    sr_Latn    sr    sv    ta    te    uk    zh_CN zh_TW)
PUBLAN=(as-IN bn-IN ca-ES cs-CZ da-DK de-DE el-GR es-ES fi-FI fr-FR gu-IN he-IL hi-IN hr-HR hu-HU id-ID it-IT ja-JP kn-IN ko-KR ml-IN mr-IN ms-MY nb-NO nl-NL or-IN pa-IN pl-PL pt-BR pt-PT ru-RU sk-SK sr-Latn-RS sr-RS sv-SE ta-IN te-IN uk-UA zh-CN zh-TW)

#
#  Merge the po's and move them to the target
#
for NUM in {0..39} ; do
    mv po/${TFXLAN[${NUM}]}.po po/${PUBLAN[${NUM}]}.po
    mkdir ${PUBLAN[${NUM}]}
    for POTFILE in pot/*.pot; do
        msgmerge po/${PUBLAN[${NUM}]}.po ${POTFILE} | msgattrib --no-obsolete  \
                 > ${PUBLAN[${NUM}]}/$(basename ${POTFILE} .pot).po
    done
    cp -r ${PUBLAN[${NUM}]} $TARG
  done
#make update-po-all
#
# Build the .omf files
#
sed -i 's|Fedora Release Notes|Release Notes for Fedora 11|g' en-US/fedora-release-notes.omf.in
xml2po -e -o po/release-notes.pot en-US/Release_Notes.xml en-US/Article_Info.xml en-US/rpm-info.xml
mkdir omf
for NUM in {0..39} ; do
  LANG=${PUBLAN[$NUM]}
  FLAN=${TFXLAN[$NUM]}
  if [ ! -f po/$LANG.po ]; then cp po/release-notes.pot po/$LANG.po; else msgmerge -U -q po/$LANG.po po/release-notes.pot; touch po/$LANG.po; fi
  mkdir -p $LANG
  pushd po && xml2po -e -p $LANG.po ../en-US/fedora-release-notes.omf.in >../$LANG/fedora-release-notes.omf.in && popd
  sed -e "s!@RELEASE@!$VER!g" $LANG/fedora-release-notes.omf.in > omf/fedora-release-notes-$FLAN.omf
  sed -i "s!@DATE@!$RELDATE!g" omf/fedora-release-notes-$FLAN.omf
  sed -i "s!@LANG@!$LANG!g" omf/fedora-release-notes-$FLAN.omf
  sed -i "s!@LANGC@!$FLAN!g" omf/fedora-release-notes-$FLAN.omf
done
sed -e "s!@RELEASE@!$VER!g" en-US/fedora-release-notes.omf.in > omf/fedora-release-notes-C.omf
sed -i "s!@DATE@!$RELDATE!g" omf/fedora-release-notes-C.omf
sed -i "s!@LANG@!en-US!g" omf/fedora-release-notes-C.omf
sed -i "s!@LANGC@!C!g" omf/fedora-release-notes-C.omf
#
#  Now move everything to the target
#
cp -r en-US $TARG
cp -r omf $TARG
cd $TARG
cd ..
tar -czf ../rpm/fedora-release-notes-${VER}.tar.gz fedora-release-notes-${VER}
popd

