\ProvidesFile{biblatex-gost.def}
[2021/05/08\space v1.22\space biblatex-gost styles]

% these declarations should be here, not in lbx, to be initialized for all languages
\NewBibliographyString{
  involumes,
  geneditor,
  geneditors,
  bypreparation,
  bygeneditor,
  bygeneditortr,
  bygeneditorco,
  bygeneditoran,
  bygeneditorin,
  bygeneditorfo,
  bygeneditoraf,
  bygeneditortrco,
  bygeneditortran,
  bygeneditortrin,
  bygeneditortrfo,
  bygeneditortraf,
  bygeneditorcoin,
  bygeneditorcofo,
  bygeneditorcoaf,
  bygeneditoranin,
  bygeneditoranfo,
  bygeneditoranaf,
  bygeneditortrcoin,
  bygeneditortrcofo,
  bygeneditortrcoaf,
  bygeneditortranin,
  bygeneditortranfo,
  bygeneditortranaf,
  bycompilertr,
  bycompilerco,
  bycompileran,
  bycompilerin,
  bycompilerfo,
  bycompileraf,
  bycompilertrco,
  bycompilertran,
  bycompilertrin,
  bycompilertrfo,
  bycompilertraf,
  bycompilercoin,
  bycompilercofo,
  bycompilercoaf,
  bycompileranin,
  bycompileranfo,
  bycompileranaf,
  bycompilertrcoin,
  bycompilertrcofo,
  bycompilertrcoaf,
  bycompilertranin,
  bycompilertranfo,
  bycompilertranaf,
  gecompiler,
  gecompilers,
  bygecompiler,
  bygecompilertr,
  bygecompilerco,
  bygecompileran,
  bygecompilerin,
  bygecompilerfo,
  bygecompileraf,
  bygecompilertrco,
  bygecompilertran,
  bygecompilertrin,
  bygecompilertrfo,
  bygecompilertraf,
  bygecompilercoin,
  bygecompilercofo,
  bygecompilercoaf,
  bygecompileranin,
  bygecompileranfo,
  bygecompileranaf,
  bygecompilertrcoin,
  bygecompilertrcofo,
  bygecompilertrcoaf,
  bygecompilertranin,
  bygecompilertranfo,
  bygecompilertranaf,
  byeditorcollaborator,
  books,
  parts,
  issues,
  mediavideorecording,
  mediasoundrecording,
  mediagraphic,
  mediacartographic,
  mediakit,
  mediamotionpicture,
  mediamicroform,
  mediamultimedia,
  mediamusic,
  mediaobject,
  mediamanuscript,
  mediatext,
  mediabraille,
  mediaeresource,
  updated,
  systemreq,
  countryru,countryussr,patentru,patentussr,patreqru,patrequssr,invcert,
  requested,published,priority,
  docthesis,phdautoref,docautoref,
}

% \DeclareLanguageMappingSuffix{-gost} doesn't play
% well with american/british/english
%
% \DeclareLanguageMappingSuffix{-gost}
\DeclareLanguageMapping{american}{american-gost}
\DeclareLanguageMapping{brazilian}{brazilian-gost}
\DeclareLanguageMapping{british}{british-gost}
\DeclareLanguageMapping{catalan}{catalan-gost}
\DeclareLanguageMapping{croatian}{croatian-gost}
\DeclareLanguageMapping{english}{english-gost}
\DeclareLanguageMapping{french}{french-gost}
\DeclareLanguageMapping{galician}{galician-gost}
\DeclareLanguageMapping{german}{german-gost}
\DeclareLanguageMapping{greek}{greek-gost}
\DeclareLanguageMapping{icelandic}{icelandic-gost}
\DeclareLanguageMapping{italian}{italian-gost}
\DeclareLanguageMapping{portuguese}{portuguese-gost}
\DeclareLanguageMapping{russian}{russian-gost}
\DeclareLanguageMapping{slovene}{slovene-gost}
\DeclareLanguageMapping{spanish}{spanish-gost}

%
%   Sorting Schemes
%
\DeclareSortingTemplate{nty}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sortvolume}
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
}

\DeclareSortingTemplate{nyvt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sortvolume}
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
}

\DeclareSortingTemplate{ynt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
  }
  \sort{
    \field{sortyear}
    \field{year}
    \literal{9999}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
}

\DeclareSortingTemplate{ydnt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
  }
  \sort[direction=descending]{
    \field[strside=left,strwidth=4]{sortyear}
    \field[strside=left,strwidth=4]{year}
    \literal{9999}
  }
  \sort{
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
}

\DeclareSortingTemplate{nyt}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortvolume}
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
}

\DeclareSortingTemplate{ntvy}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortvolume}
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
}

\DeclareSortingTemplate{anyt}{
  \sort{
    \field{presort}
  }
  \sort{
    \field{labelalpha}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
}

\DeclareSortingTemplate{anyvt}{
  \sort{
    \field{presort}
  }
  \sort{
    \field{labelalpha}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{heading}
    \field{sortname}
    \field{author}
    \field{editor}
    \field{translator}
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
  \sort{
    \field{sortyear}
    \field{year}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{volume}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{book}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{part}
    \literal{0000}
  }
  \sort{
    \field[padside=left,padwidth=4,padchar=0]{issue}
    \literal{0000}
  }
  \sort{
    \field{sorttitle}
    \field{maintitle}
    \field{title}
  }
}

\DeclareSortExclusion{inbook,incollection,inproceeding,bookinbook,suppbook,suppcollection,inreference}
  {editor,volume,maintitle}

\DeclareLabelname{%
  \field{shortauthor}
  \field{author}
  \field{shorteditor}
  \field{editor}
  \field{translator}
}

\DeclareLabeltitle[book,collection,reference,proceedings]{%
  \field{shorttitle}
  \field{maintitle}
  \field{title}}

\DeclareDataInheritance{*}{*}{%
  \noinherit{heading}}
\DeclareDataInheritance{periodical}{article}{%
  \noinherit{endyear}\noinherit{endmonth}\noinherit{endday}
  \inherit{credits}{journalcredits}}
\DeclareDataInheritance{mvbook,mvcollection,mvproceedings}
  {book,collection,inbook,incollection,inproceedings}{%
  \noinherit{endyear}\noinherit{endmonth}\noinherit{endday}}
\DeclareDataInheritance{mvbook,mvcollection,mvproceedings,mvreference}
  {book,collection,proceedings,reference}{%
  \inherit{shorttitle}{shorttitle}}

\DeclareDataInheritance{article}{periodical}{%
  \noinherit{pagetotal}}
\DeclareDataInheritance{book}{inbook,bookinbook,suppbook}{%
  \inherit{translator}{booktranslator}
  \inherit{introduction}{bookintroduction}
  \inherit{commentator}{bookcommentator}
  \inherit{annotator}{bookannotator}
  \inherit{foreword}{bookforeword}
  \inherit{afterword}{bookafterword}
  \inherit{origlanguage}{bookoriglanguage}
  \inherit{credits}{bookcredits}
  \noinherit{pagetotal}}
\DeclareDataInheritance{collection,reference}{incollection,inreference,suppcollection}{%
  \inherit{translator}{booktranslator}
  \inherit{introduction}{bookintroduction}
  \inherit{commentator}{bookcommentator}
  \inherit{annotator}{bookannotator}
  \inherit{foreword}{bookforeword}
  \inherit{afterword}{bookafterword}
  \inherit{origlanguage}{bookoriglanguage}
  \inherit{credits}{bookcredits}
  \noinherit{pagetotal}}
\DeclareDataInheritance{proceedings}{inproceedings}{%
  \inherit{translator}{booktranslator}
  \inherit{introduction}{bookintroduction}
  \inherit{commentator}{bookcommentator}
  \inherit{annotator}{bookannotator}
  \inherit{foreword}{bookforeword}
  \inherit{afterword}{bookafterword}
  \inherit{origlanguage}{bookoriglanguage}
  \inherit{credits}{bookcredits}
  \noinherit{pagetotal}}

% Related

\renewbibmacro*{related:bytranslator}[1]{%
  \entrydata{#1}{%
    \renewbibmacro*{name:hook}[1]{%
      \ifnumequal{\value{listcount}}{1}
        {\mkrelatedstringtext{\lbx@initnamehook{#1}}}
        {}}%
    \printnames[bytranslator]{translator}%
    \setunit*{\addspace\bibstring[\mkrelatedstringtext]{astitle}\space}%
    \usebibmacro{author}%
    \setunit*{\labelnamepunct}%
    \usebibmacro{title}%
    \setunit{\addspace}%
    \printtext[parens]{%
      \printlist{location}%
      \iflistundef{publisher}
        {\setunit*{\addcomma\space}}
        {\setunit*{\addcolon\space}}%
      \printlist{publisher}%
      \setunit*{\addcomma\space}%
      \usebibmacro{date}}}}

\renewbibmacro*{related:multivolume}[1]{%
  \entrydata*{#1}{%
    \usebibmacro{volume+parts}{\newunit}%
    \setunit{\addcolondelim}%
    \ifboolexpr{
      test {\ifnamesequal{author}{savedauthor}}
      or
      test {\ifnameundef{author}}
    }
      {}
      {\usebibmacro{author}%
       \setunit*{\labelnamepunct}}%
    \usebibmacro{title}%
    \setunit{\respdelim}%
    \iflistsequal{credits}{savedcredits}
      {}
      {\usebibmacro{credits}}%
    \setunit*{\resppunct}%
    \ifnamesequal{editor}{savededitor}
      {}
      {\usebibmacro{byeditor}}%
    \setunit*{\resppunct}%
    \ifnamesequal{translator}{savedtranslator}
      {}
      {\usebibmacro{bytranslator+others}}%
    \newunit\newblock
    \usebibmacro{date}%
    \newunit\newblock
    \printfield{pagetotal}%
    \usebibmacro{finentry}}}

\endinput
