16
$\begingroup$

In 10.3, Mathematica starts captioning symbol-names into foreign languages if your Interface preferences are set to have Mathematica in a foreign language.

Graph annotated

I poked around the Attributes, and viewed the Cell expression, but from the code I couldn't find any sign that this was happening at all (though it's obviously happening somehow).

I want to be able to make this happen on my own functions: to be able to supply translations, for instance, or extremely short inline explanations. For example, if I made a little function toInt, I might want to attach a type annotation String->Integer. This could help offset the verbosity of Mathematica code by making the notebook interface that little bit more intelligent.

One can see the translations available using WolframLanguageData:

WolframLanguageData[Graph][
 EntityProperty["WolframLanguageSymbol", "Translations"]
]

How does Mathematica do the translation annotations, and how can I do it myself?

$\endgroup$
1
  • $\begingroup$ +1 I would really like to know the answer too! $\endgroup$
    – Silvia
    Oct 23, 2015 at 7:11

1 Answer 1

12
+50
$\begingroup$

Edit

Karsten 7. suggested a better method in the comments, which does not require a modification of any system files and can be used under English language setting. It works on my 10.2 installation after applying the following procedures:

  1. Under the user's directory (FileNameJoin[{$UserBaseDirectory,"SystemFiles\\FrontEnd\\SystemResources\\FunctionalFrequency"}]), add a file named, say, CustomAnnotation.m.

  2. Edit this CustomAnnotation.m as you want, consisting with the format of the built-in language specification file as described in my old answer (see below).

  3. Either open the Option Inspector and add the following path to Global Options ► File Locations ► PrivatePaths ► "TranslationData":

    FrontEnd`FileName[{$UserBaseDirectory, "SystemFiles", "FrontEnd", "SystemResources", "FunctionalFrequency"}]
    

    or execute the following code within the notebook:

    CurrentValue[$FrontEnd, {PrivatePaths, "TranslationData"}] = 
     Append[CurrentValue[$FrontEnd, {PrivatePaths, "TranslationData"}], 
       FrontEnd`FileName[{$UserBaseDirectory, "SystemFiles", "FrontEnd", 
         "SystemResources", "FunctionalFrequency"}]];
    
  4. Restart Mathematica.

  5. Execute the following code in Mathematica (replace $FrontEnd with $FrontEndSession for non-persistent modification):

    SetOptions[$FrontEnd, TranslationOptions -> {"Enabled" -> True, 
                                                 "Language" -> "CustomAnnotation"}]
    

Original Answer

NOTE:

  1. The following method works on my Mathematica 10.2, but not tested on other versions. [Also tested on Mathematica 10.3, Mac OS 10.11.1.]
  2. The following method involving modification of a system file, thus is likely prohibited by the EULA.

  1. First find the language specific file located on a path similar to the following (I will use the simplified Chinese as a demonstration):

    C:\Program Files\Wolfram Research\Mathematica\10.2\SystemFiles\FrontEnd\SystemResources\FunctionalFrequency\ChineseSimplified.m

  2. Add a new function annotation line (the 3rd line in the snapshot):

    Mathematica graphics

  3. Open Mathematica with language setting to simplified Chinese, type ThisIsATestFunction in a notebook:

    Mathematica graphics

$\endgroup$
6
  • $\begingroup$ This is great - I'd still like a way to do this without changing the system language, but that's looking increasingly unlikely given how it seems to have been implemented. $\endgroup$ Oct 23, 2015 at 8:38
  • $\begingroup$ @PatrickStevens I doubt there is any way without changing system files.. $\endgroup$
    – Silvia
    Oct 23, 2015 at 8:44
  • $\begingroup$ @Karsten7. I would like to know how to make it work under english language settings. $\endgroup$
    – Silvia
    Oct 23, 2015 at 8:47
  • $\begingroup$ @Karsten7. I edited your method in my answer, please feel free to correct me if there is any misunderstanding. $\endgroup$
    – Silvia
    Oct 23, 2015 at 13:37
  • $\begingroup$ This method seems to be limited to function names starting with a capital letter or $, though. $\endgroup$
    – Karsten7
    Oct 23, 2015 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.