# Translator doesn't work in external pgfplot legend

I would like to have my pgfplot legend automatically translated wrt the language used in my article. Thus, I use to use the translator package, which a very easy and pleasant solution. It works like a charm until I externalize the legend into a reference.

In the follow MWE, one can observe that the translate command works in nameref, in legend entries but not with legend to name.

    \documentclass{article}
\usepackage[english,french]{babel}
\usepackage{translator}
\languagepath{French}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}
\usepackage{nameref}

\begin{document}
\providetranslation[to=French]{My section}{Ma section}%
\section{\translate{My section}\label{marker}}
In section \nameref{marker} we defined...

\begin{figure}[!h]
\centering
\begin{tikzpicture}
\providetranslation[to=French]{Zero line}{Ligne zéro}%
\end{axis}
\end{tikzpicture}
\caption{Figure with internal legend}
\end{figure}
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\providetranslation[to=French]{Zero line}{Ligne zéro}%
\begin{axis}[ymin=0, ymax=80,legend entries={\translate{Zero line},\translate{Quadratic line}},legend to name=legend]
\end{axis}
\end{tikzpicture}
\caption{Figure with external legend}
\ref{legend}\newline
\end{figure}
\end{document}


producing:

Is there a way to solve that issue ?

-

The external legend gets put into its own tikzpicture environment, so your translations aren't available when the legend gets put together. If you provide the translations outside the tikzpicture, everything works fine:

\documentclass{article}
\usepackage[english,french]{babel}
\usepackage{translator}
\languagepath{French}

\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}
\usepackage{nameref}

\providetranslation[to=French]{Zero line}{Ligne zéro}%

\begin{document}
\providetranslation[to=French]{My section}{Ma section}%
\section{\translate{My section}\label{marker}}
In section \nameref{marker} we defined...

\begin{figure}[!h]
\centering

\begin{tikzpicture}
\begin{axis}[ymin=0, ymax=80,legend entries={\translate{Zero line},\translate{Quadratic line}},legend to name=legend]

You right... More specifically, the translation need to be declare in the same environment than the one where \ref is used or upper (like you do, in the preamble for example). Thanks –  Sigmun Apr 17 '12 at 14:35