]> hydra-www.ietfng.org Git - mcv-academic/commitdiff
Add support for multiple languages dinamically
authoradin <adin@ic.unicamp.br>
Wed, 5 Jul 2017 21:49:03 +0000 (18:49 -0300)
committeradin <adin@ic.unicamp.br>
Wed, 5 Jul 2017 21:49:03 +0000 (18:49 -0300)
academic.sty
cv.bbx
cv.dbx
portuguese-cv.lbx [new file with mode: 0644]
setlanguages.sty

index 819439476c160d8a5f17c59695b587d1d102346a..b10b9d07c8fc8a4106ac1da2f975ab62183a265c 100644 (file)
@@ -1,6 +1,5 @@
 %% start of file `academic.sty'.
 
-
 %-------------------------------------------------------------------------------
 %                identification
 %-------------------------------------------------------------------------------
@@ -19,7 +18,9 @@
 % Options
 %-------------------------------------------------------------------------------
 \RequirePackage{pgfkeys}
+\RequirePackage{pgffor}
 \RequirePackage{pgfopts}
+\RequirePackage{etoolbox}
 
 % Package options
 \def\unknown@packageoptions{}
@@ -70,7 +71,6 @@
   \moderncvstyle{\@load@style}
 }
 
-
 %-------------------------------------------------------------------------------
 % Multilanguage support
 %-------------------------------------------------------------------------------
 
 % Create long names for languages, this reuses the code from cv.bbx
 % fixme: merge both definitions (here and cv.bbx)
-\pgfkeys{
+\def\@cv@shortnamelist{}
+\def\@cv@longnamelist{}
+\def\@coma{}
+\pgfkeys{%
   /shortlan/.is family, /shortlan,
-  .unknown/.code = {
-     \expandafter\edef\csname @cv@short@#1\endcsname{\pgfkeyscurrentname}
-     \expandafter\expandafter\expandafter\edef\expandafter\csname @cv@long@\pgfkeyscurrentname\endcsname{#1}
+  .unknown/.code = {%
+    \edef\@cv@shortnamelist{\@cv@shortnamelist\@coma\pgfkeyscurrentname}%
+    \edef\@cv@longnamelist{\@cv@longnamelist\@coma#1}%
+    \def\@coma{,}%
+    \expandafter\edef\csname @cv@short@#1\endcsname{\pgfkeyscurrentname}%
+    \expandafter\expandafter\expandafter\edef\expandafter\csname @cv@long@\pgfkeyscurrentname\endcsname{#1}%
   }
 }
-%\pgfkeys{
-%  /shortlan/.is family, /shortlan,
-%  .unknown/.code = {
-%    \expandafter\edef\csname @cv@short@#1\endcsname{\pgfkeyscurrentname}
-%  }
-%}
 % handler to create the keys
-\def\babelshortnames#1{\pgfkeys{/shortlan, #1}}
+\def\babelshortnames#1{\def\@coma{}\pgfkeys{/shortlan, #1}}
 % directly obtain the short name
 \newcommand{\shortlanguagename}{\csname @cv@short@\languagename\endcsname}
 \newcommand{\longlanguagename}[1]{\csname @cv@long@#1\endcsname}
 
+% Setter for mappings
+\def\@default@mappings{%
+\foreach \@cv@lang in \@cv@longnamelist {%
+  % define the mapping into a macro and then expand it
+  \begingroup\edef\x{\endgroup\noexpand\DeclareLanguageMapping{\@cv@lang}{\@cv@lang-cv}}
+  \x
+}}
+
+% Functions for creating the dbx
+% \localized{text}{\macroToStoreInto}
+\newcommand{\@cv@localize}[3][]{%
+  \def\@coma{#1}
+  \foreach \@cv@lang in \@cv@shortnamelist{%
+    \global\edef#3{#3\@coma#2-\@cv@lang}%
+    \global\def\@coma{,}%
+  }%
+}
+
+\newcommand{\@cv@localizeList}[2]{%
+  \def\@@coma{}
+  \foreach \@word in #1{%
+    \@cv@localize[\@@coma]{\@word}{#2}%
+    \global\def\@@coma{,}%
+  }%
+}
+
+\newcommand{\localizedmacro}[3][]{
+  \ifdefmacro{#3}
+    {\let\@list#3}
+    {\def\@list{#3}}
+  \def\@localized{}%
+  \@cv@localizeList{\@list}{\@localized}%
+  \begingroup\edef\x{\endgroup\noexpand#2[#1]{#3,\@localized}}%
+  \x%
+}
+
+\newcommand{\DeclareLocalizedDatamodelFields}[2][]{%
+  \localizedmacro[#1]{\DeclareDatamodelFields}{#2}%
+}
+
+\newcommand{\DeclareLocalizedDatamodelEntryfields}[2][]{%
+  \localizedmacro[#1]{\DeclareDatamodelEntryfields}{#2}%
+}
+
 % declare default languages
 % \babelshortnames{en=english, es=spanish}
 % or imported to be in sync with cv.bbx
 % Academic drivers and sorting to use with this style
 %-------------------------------------------------------------------------------
 
-%\RequirePackage[tools={study, position, course, thesis, project, cvmisc}, bibstyle=numeric-comp]{biblatex-multiple-dm}
-%\RequirePackage[tools={cv, numeric-comp}, bibstyle=numeric-comp]{biblatex-multiple-dm}
-
-% bibliography with mutiple entries
-
 % If there is no custom datamodel, load defaul cv.dbx
 \IfFileExists{cv-\@load@style.dbx}%
   {\def\@load@datamodel{cv-\@load@style}}%
 
 \RequirePackage[backend=biber, citestyle=numeric-comp, bibstyle=\@load@bibstyle, datamodel=\@load@datamodel, sorting=ymdtn, maxbibnames=99, defernumbers=true, giveninits=true, sortcites]{biblatex}
 
+
+% Execute mappings (these must be after biblatex loaded, since we will use the \DeclareLangaugeMapping macro)
+\@default@mappings
+\@custom@mappings
+
 % Patch endyears that are not declared
 % http://tex.stackexchange.com/a/327884/7561
 \DeclareSourcemap{
 \fi
 
 
-%% Patch the bibliography
-%
-%% lets remove the brackets
-%\DeclareFieldFormat{labelnumberwidth}{#1.}
-%
-%% http://tex.stackexchange.com/a/123809/7561
-%\defbibenvironment{bibliography}{
-%\list
-%  {\printtext[labelnumberwidth]{% label format from numeric.bbx
-%      \printfield{labelprefix}%
-%      \printfield{labelnumber}}}
-%  {
-%    \ifthenelse{\equal{\@load@style}{banking}}{%
-%      \setlength{\topsep}{0pt}%
-%%      \setlength{\leftmargin}{2em}%
-%      \setlength{\labelwidth}{1.5em}%
-%      \setlength{\labelsep}{\separatorcolumnwidth}%
-%%      \setlength{\itemindent}{0em}%
-%      \leftmargin\labelwidth%
-%      \advance\leftmargin\labelsep%
-%    }{
-%      \setlength{\topsep}{0pt}%
-%      \setlength{\labelwidth}{\hintscolumnwidth}%
-%      \setlength{\labelsep}{\separatorcolumnwidth}%
-%      \leftmargin\labelwidth%
-%      \advance\leftmargin\labelsep%
-%    }%
-%%    \setlength{\topsep}{0pt}% layout parameters from moderncvstyleclassic.sty
-%%    \setlength{\labelwidth}{\hintscolumnwidth}%
-%%    \setlength{\labelsep}{\separatorcolumnwidth}%
-%%    \leftmargin\labelwidth%
-%%    \advance\leftmargin10pt%
-%%    \advance\leftmargin\labelsep
-%  }%
-%  \sloppy\clubpenalty4000\widowpenalty4000}
-%{\endlist}
-%{\item}
-%
-%% New environment withouth the list indent
-%\defbibenvironment{nobibenv}{%
-%  \list{}{%
-%    \ifboolexpr{ (test{\ifdefstring{\@load@style}{classic}} or test{\ifdefstring{\@load@style}{casual}}) }{%
-%      \setlength{\topsep}{0pt}%
-%      \setlength{\labelwidth}{\hintscolumnwidth}%
-%      \setlength{\labelsep}{\separatorcolumnwidth}%
-%      \setlength{\leftmargin}{0pt}%
-%    }{%
-%    \ifthenelse{\equal{\@load@style}{oldstyle}}{%
-%      \setlength{\topsep}{0pt}%
-%      \setlength{\labelwidth}{\hintscolumnwidth}%
-%      \setlength{\labelsep}{\separatorcolumnwidth}%
-%      \leftmargin\labelwidth%
-%      \advance\leftmargin\labelsep%
-%    }{%
-%    \ifthenelse{\equal{\@load@style}{banking}}{%
-%      \setlength{\topsep}{0pt}%
-%      \setlength{\labelwidth}{0pt}%
-%      \setlength{\labelsep}{0pt}%
-%      \setlength{\leftmargin}{0pt}%
-%    }{
-%      \setlength{\topsep}{0pt}%
-%      \setlength{\labelwidth}{\hintscolumnwidth}%
-%      \setlength{\labelsep}{\separatorcolumnwidth}%
-%      \setlength{\leftmargin}{0pt}%
-%    }%
-%    }%
-%    }%
-%    \setlength{\parsep}{0pt}%
-%  }%
-%}%
-%{\endlist}
-%{\item}
 
 %-------------------------------------------------------------------------------
 % Factory for the printbibliography replacements
 % Patching moderncv
 %-------------------------------------------------------------------------------
 
-%\RequirePackage{xpatch}
-%% Patch blank printing
-%\newcommand{\ifnoprint}[3]{%
-%  \setbox0=\hbox{#1\unskip}\ifdim\wd0=0pt%
-%  #2\else#3\fi%
-%}
-
-% Patch cventry for better blank support
-%\xpatchcmd{\cventry}%
-%{\ifthenelse{\equal{#4}{}}}%
-%{\ifnoprint{#4}}%
-%{}{\PackageWarning{academic}{Error patching \noexpand\cventry}}%
-%
-%\xpatchcmd{\cventry}%
-%{\ifthenelse{\equal{#5}{}}}%
-%{\ifnoprint{#5}}%
-%{}{\PackageWarning{academic}{Error patching \noexpand\cventry}}%
-%
-%\xpatchcmd{\cventry}%
-%{\ifthenelse{\equal{#6}{}}}%
-%{\ifnoprint{#6}}%
-%{}{\PackageWarning{academic}{Error patching \noexpand\cventry}}%
-%
-%% Patch the comments on the entries to avoid spurious white space
-%\xpatchcmd{\cventry}%
-%{\ifx}%
-%{\ifdetails\ifx}%
-%{}{\PackageWarning{academic}{Error patching \noexpand\cventry}}%
-%
-%\xpatchcmd{\cventry}%
-%{\fi}%
-%{\fi\fi}%
-%{}{\PackageWarning{academic}{Error patching \noexpand\cventry}}%
-
 % Patch socials
 \RenewDocumentCommand{\social}{O{}O{}m}{%
   \ifthenelse{\equal{#2}{}}%
diff --git a/cv.bbx b/cv.bbx
index fa8809b01dccaca1f5f746047f468ec25b9caa80..70928d5dbb4962e3c8736ab4fce7602b52202c42 100755 (executable)
--- a/cv.bbx
+++ b/cv.bbx
 % Language handlers
 %-------------------------------------------------------------------------------
 
-\DeclareLanguageMapping{english}{english-cv}
-\DeclareLanguageMapping{spanish}{spanish-cv}
-
-%\pgfkeys{
-%  /shortlan/.is family, /shortlan,
-%  .unknown/.code = {
-%    \expandafter\edef\csname @cv@short@#1\endcsname{\pgfkeyscurrentname}
-%  }
-%}
-%% handler to create the keys
-%\def\babelshortnames#1{\pgfkeys{/shortlan, #1}}
-%% directly obtain the short name
-%\def\shortlanguagename{\csname @cv@short@\languagename\endcsname}
-%%\def\longlanguagename[1]{\csname @cv@long@#1\endcsname}
-%
-%%% declare default languages
-%%% \babelshortnames{en=english, es=spanish}
-%%% or imported to be in sync with moderncvstyleacademic.sty
-%\input{setlanguages.sty}
-
-%% Bibliography strings
-%\NewBibliographyString{
-%  duration,years,year,
-%  pi,ai,professor,researcher,
-%  assisprofessor, assocprofessor,
-%  present,presentabbr}
-%
-%\DefineBibliographyStrings{english}{%
-%  duration = {time frame},
-%  years = {years},
-%  year = {year},
-%  pi = {Principal Investigator},
-%  ai = {Alternating Investigator},
-%  professor = {Professor},
-%  assisprofessor = {Assistant Professor},
-%  assocprofessor = {Associate Professor},
-%  researcher = {Researcher},
-%  %
-%  present = {present},
-%  presentabbr = {pres\adddot},
-%}
-%\DefineBibliographyStrings{spanish}{%
-%  duration = {duraci\'on},
-%  years = {a\~nos},
-%  year = {a\~no},
-%  pi = {Investigador Principal},
-%  ai = {Investigador Alterno},
-%  professor = {Profesor},
-%  assisprofessor = {Profesor Asistente},
-%  assocprofessor = {Profesor Asociado},
-%  researcher = {Investigador},
-%  %
-%  present = {presente},
-%  presentabbr = {pres\adddot},
-%}
-%
-% Extra definitions for languages
-
-%
-%\DefineBibliographyExtras{english}{%
-%%  \renewcommand*{\datesep}{\space}%
-%}
-%\DefineBibliographyExtras{spanish}{%
-%  \renewcommand*{\bibrangedash}{--}
-%  \renewcommand*{\bibdatedash}{--}
-%%  \renewcommand*{\datesep}{\space}
-%}
-
 % Multi language macros
 \newbibmacro*{langfield}[1]{%
 \expandafter\iffieldundef\expandafter{#1-\shortlanguagename}{\printfield{#1}}{\expandafter\printfield\expandafter{#1-\shortlanguagename}}%
diff --git a/cv.dbx b/cv.dbx
index 4849584f6882257f9e22924d183013ba31378d33..f8b28a9b459b39be4fc1a1be649cf63a50d22679 100644 (file)
--- a/cv.dbx
+++ b/cv.dbx
@@ -1,34 +1,6 @@
 \ProvidesFile{cv.dbx}
 
-\DeclareDatamodelFields[type=field, datatype=literal]{
-  level,%
-  period,%
-  %
-  organization,%
-  title,%
-  country,%
-  description,%
-  funding,
-  role,%
-  note,%
-  %
-  organization-es,%
-  title-es,%
-  country-es,%
-  description-es,%
-  funding-es,
-  role-es,
-  note-es,%
-  %
-  organization-en,%
-  title-en,%
-  country-en,%
-  description-en,%
-  funding-en,%
-  role-en,%
-  note-en%
-}
-
+\DeclareLocalizedDatamodelFields[type=field, datatype=literal]{level, period, title, organization, country, description, funding, role, note}
 
 \DeclareDatamodelFields[type=list, datatype=literal]{
   number
 \DeclareDatamodelEntrytypes{course, cvmisc, position, project, study, thesis}
 
 % Data models
-
-\DeclareDatamodelEntryfields[course]{%
+\DeclareLocalizedDatamodelEntryfields[course]{%
   date,%
   organization,%
   title,%
-  description,%
-  %
-  organization-es,%
-  title-es,%
-  description-es,%
-  %
-  organization-en,%
-  title-en,%
-  description-en%
+  description%
 }
 
-\DeclareDatamodelEntryfields[cvmisc]{%
+\DeclareLocalizedDatamodelEntryfields[cvmisc]{%
   date,%
   title,%
-  description,%
-  %
-  title-es,%
-  description-es,%
-  %
-  title-en,%
-  description-en%
+  description%
 }
 
-\DeclareDatamodelEntryfields[position]{%
+\DeclareLocalizedDatamodelEntryfields[position]{%
   date,%
   organization,%
   title,%
   country,%
-  description,%
-  %
-  organization-es,%
-  title-es,%
-  country-es,%
-  description-es,%
-  %
-  organization-en,%
-  title-en,%
-  country-en,%
-  description-en%
+  description%
 }
 
-\DeclareDatamodelEntryfields[project]{
+\DeclareLocalizedDatamodelEntryfields[project]{
   number,
   title,
   funding,
-  role,
-  %
-  title-en
-  funding-en,
-  role-en,
-  %
-  title-es,
-  funding-es,
-  role-es,
-  %
+  role,%
   number,
   period,
   month,
   year%
 }
 
-\DeclareDatamodelEntryfields[study]{%
+\DeclareLocalizedDatamodelEntryfields[study]{%
   date,%
   organization,%
   title,%
   country,%
-  description,%
-  %
-  organization-es,%
-  title-es,%
-  country-es,%
-  description-es,%
-  %
-  organization-en,%
-  title-en,%
-  country-en,%
-  description-en%
+  description%
 }
 
-\DeclareDatamodelEntryfields[thesis]{%
+\DeclareLocalizedDatamodelEntryfields[thesis]{%
   author,%
   date,%
   organization,%
   title,%
   note,%
-  level,%
-  %
-  organization-es,%
-  title-es,%
-  note-es,%
-  %
-  organization-en,%
-  title-en,%
-  note-en%
+  level%
 }
diff --git a/portuguese-cv.lbx b/portuguese-cv.lbx
new file mode 100644 (file)
index 0000000..c6470d6
--- /dev/null
@@ -0,0 +1,62 @@
+\ProvidesFile{portuguese-cv.lbx}
+\InheritBibliographyExtras{portuguese}
+
+% Bibliography strings
+\NewBibliographyString{
+  duration,
+  years,
+  year,
+  pi,
+  ai,
+  professor,
+  researcher,
+  assisprofessor, 
+  assocprofessor,
+  present,
+  studies,%
+  positions,%
+  theses, 
+  undergrad, 
+  master, 
+  doctor, 
+  degree,%
+  courses,%
+  cvmiscs%
+}
+
+\DeclareBibliographyStrings{%
+  inherit = {portuguese},
+  duration = {{dura\c{c}\~ao}{dura\c{c}\~ao}},
+  years = {{anos}{anos}},
+  year = {{ano}{ano}},
+  pi = {{Pesquisador Principal}{Pesquisador Principal}},
+  ai = {{Pesquisador Alternativo}{Pesquisador Alternativo}},
+  professor = {{Professor}{Professor}},
+  assisprofessor = {{Profesor Assistente}{Profesor Assistente}},
+  assocprofessor = {{Profesor Associado}{Profesor Associado}},
+  researcher = {{Pesquisador}{Pesquisador}},
+  %
+  present = {{presente}{pres\adddot}},
+  %
+  studies = {{Educa\c{c}\~ao}{Educa\c{c}\~ao}},
+  positions = {{Posi\c{c}\~oes}{Posi\c{c}\~oes}},
+  %
+  theses = {{Teses}{Teses}},
+  degree = {{Grau}{Grau}},
+  undergrad = {{Gradua\c{c}\~ao}{Gradua\c{c}\~ao}},
+  master = {{Mestrado}{Mestrado}},
+  doctor = {{Doutorado}{Doutorado}},
+  %
+  courses = {{Disciplinas}{Disciplinas}},%
+  %
+  cvmiscs = {{Diversos}{Diversos}},
+}
+
+
+\DeclareBibliographyExtras{%
+  \renewcommand*{\bibrangedash}{--}
+  \renewcommand*{\bibdatedash}{--}
+}
+
+
+\endinput
\ No newline at end of file
index 903f0d9b743441e3e2005dbf1076bd8b8a22098f..fda7c1fa9e90d17f2512289e326a1874b99eac66 100644 (file)
@@ -1,3 +1,8 @@
 % Declare the languages map that you want to use
 
-\babelshortnames{en=english, es=spanish}
+\babelshortnames{en=english, es=spanish, pt=portuguese}
+
+% You can declare custom mappings here
+\def\@custom@mappings{%
+%  \DeclareLanguageMapping{custom}{custom-cv}
+}
\ No newline at end of file