本文介绍了AmCharts v4 AmMap更改语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改ammap(V4)的语言.

I would like to change the language of a ammap (V4).

因此,我按照此处提供的示例进行操作(但适用于V3): http://jsfiddle .net/tDqs2/25/

Therefore I followed the example which is provided here (but it is for V3): http://jsfiddle.net/tDqs2/25/

首先,通过script标签加载语言.

Here first the language get loaded via a script tag.

<script src="http://cdn.amcharts.com/lib/3/lang-maps/de.js">

现在,如果我按照说明进行操作,我将看不到任何地图.这是我的codepen: https://codepen.io/ms92o/pen/mjMpZy

Now if I follow the instructions I don't see any map.Here is my codepen:https://codepen.io/ms92o/pen/mjMpZy

该行不起作用:

chart.language = 'de';

在查看语言的API时,我确实找到了language属性: https://www.amcharts.com/docs/v4/reference/mapchart/

Looking at the API for language I do find a language property:https://www.amcharts.com/docs/v4/reference/mapchart/

但是如何设置语言?语言构造函数不需要任何参数

But how do I set the language?The language constructor does not need any parameters

let language = new am4core.Language();
// How to change that language to 'DE'.

推荐答案

德语翻译是在本月初添加的.

您可以在此处找到其他当前可用的翻译: https://github. com/amcharts/amcharts4-lang/tree/master/src

You can find other currently available translations here: https://github.com/amcharts/amcharts4-lang/tree/master/src

要将语言更改为德语,我们必须首先包含翻译,因为它不是绑定的语言环境之一:

To change the language to say, German, we have to include the translation first as it isn't one of the bundled locales:

<script src="https://www.amcharts.com/lib/4/lang/de_DE.js"></script>

然后更改语言,每个图表都有一个language属性,我们将其locale属性(即chart.language.locale)更新为所选的翻译:

Then to change the language, each chart has a language property, we update its locale property, i.e. chart.language.locale, to the translation of choice:

chart.language.locale = am4lang_de_DE;

(请注意,v4尚不支持动态更新图表的语言.如果您对此感兴趣,请订阅此GitHub问题继续发布.)

(Please note, updating the chart's language dynamically is not yet supported in v4. If it's something you're interested in, please subscribe to this GitHub issue to keep posted.)

这是一个简单的英文图表演示: https://codepen.io/team/amcharts/pen/ZRaWJQ

Here's a simple chart demo in English:https://codepen.io/team/amcharts/pen/ZRaWJQ

通过上面的代码用德语进行的相同演示: https://codepen.io/team/amcharts/pen/4d968a6f292fca2dc59d5e75b0389e0e/

Same demo in German via above code: https://codepen.io/team/amcharts/pen/4d968a6f292fca2dc59d5e75b0389e0e/

如果您想发布自己的翻译或为现有翻译做出贡献,请查看创建翻译指南.

If you would like to roll your own translation or contribute to an existing one, check out the Creating Translations guide.

这篇关于AmCharts v4 AmMap更改语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:01