Skip to content

Commit

Permalink
add Spanish translations
Browse files Browse the repository at this point in the history
  • Loading branch information
ramin-deriv committed Jan 6, 2025
1 parent 7276301 commit 0c84e42
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 54 deletions.
112 changes: 64 additions & 48 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MyApp extends StatelessWidget {
ChartLocalization.delegate,
ExampleLocalization.delegate,
],
supportedLocales: ExampleLocalization.delegate.supportedLocales,
supportedLocales: ChartLocalization.delegate.supportedLocales,
theme: ThemeData.dark(),
debugShowCheckedModeBanner: false,
home: const SafeArea(
Expand Down Expand Up @@ -377,53 +377,69 @@ class _FullscreenChartState extends State<FullscreenChart> {
child: Stack(
children: <Widget>[
ClipRect(
child: DerivChart(
mainSeries: _getDataSeries(style),
markerSeries: MarkerSeries(
_markers,
activeMarker: _activeMarker,
markerIconPainter: MultipliersMarkerIconPainter(),
),
activeSymbol: _symbol.name,
annotations: ticks.length > 4
? <ChartAnnotation<ChartObject>>[
..._sampleBarriers,
if (_sl && _slBarrier != null)
_slBarrier as ChartAnnotation<ChartObject>,
if (_tp && _tpBarrier != null)
_tpBarrier as ChartAnnotation<ChartObject>,
TickIndicator(
ticks.last,
style: const HorizontalBarrierStyle(
color: Colors.redAccent,
labelShape: LabelShape.pentagon,
hasBlinkingDot: true,
hasArrow: false,
),
visibility: HorizontalBarrierVisibility
.keepBarrierLabelVisible,
),
]
: null,
pipSize:
(_tickHistorySubscription?.tickHistory?.pipSize ?? 4)
.toInt(),
granularity: granularity == 0
? 1000 // average ms difference between ticks
: granularity * 1000,
controller: _controller,
isLive: (_symbol.isOpen) &&
(_connectionBloc.state
is connection_bloc.ConnectionConnectedState),
opacity: _symbol.isOpen ? 1.0 : 0.5,
onVisibleAreaChanged: (int leftEpoch, int rightEpoch) {
if (!_waitingForHistory &&
ticks.isNotEmpty &&
leftEpoch < ticks.first.epoch) {
_loadHistory(500);
}
},
),
child: FutureBuilder(
future: ChartLocalization.load(const Locale('es')),
builder: (_, localizationFuture) {
if (!localizationFuture.hasData) {
return const Center(
child: CircularProgressIndicator(),
);
}

return DerivChart(
mainSeries: _getDataSeries(style),
localizations:
localizationFuture.data as ChartLocalization,
markerSeries: MarkerSeries(
_markers,
activeMarker: _activeMarker,
markerIconPainter: MultipliersMarkerIconPainter(),
),
activeSymbol: _symbol.name,
annotations: ticks.length > 4
? <ChartAnnotation<ChartObject>>[
..._sampleBarriers,
if (_sl && _slBarrier != null)
_slBarrier
as ChartAnnotation<ChartObject>,
if (_tp && _tpBarrier != null)
_tpBarrier
as ChartAnnotation<ChartObject>,
TickIndicator(
ticks.last,
style: const HorizontalBarrierStyle(
color: Colors.redAccent,
labelShape: LabelShape.pentagon,
hasBlinkingDot: true,
hasArrow: false,
),
visibility: HorizontalBarrierVisibility
.keepBarrierLabelVisible,
),
]
: null,
pipSize: (_tickHistorySubscription
?.tickHistory?.pipSize ??
4)
.toInt(),
granularity: granularity == 0
? 1000 // average ms difference between ticks
: granularity * 1000,
controller: _controller,
isLive: (_symbol.isOpen) &&
(_connectionBloc.state is connection_bloc
.ConnectionConnectedState),
opacity: _symbol.isOpen ? 1.0 : 0.5,
onVisibleAreaChanged:
(int leftEpoch, int rightEpoch) {
if (!_waitingForHistory &&
ticks.isNotEmpty &&
leftEpoch < ticks.first.epoch) {
_loadHistory(500);
}
},
);
}),
),
// ignore: unnecessary_null_comparison
if (_connectionBloc != null &&
Expand Down
80 changes: 79 additions & 1 deletion lib/generated/intl/messages_es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,84 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'es';

static String m0(text) => "No hay resultados para \"${text}\"";

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{};
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"informNoResult": m0,
"labelBandsCount":
MessageLookupByLibrary.simpleMessage("Número de Bandas"),
"labelBaseLinePeriod":
MessageLookupByLibrary.simpleMessage("Período de Línea Base"),
"labelChannelFill":
MessageLookupByLibrary.simpleMessage("Relleno de Canal"),
"labelColor": MessageLookupByLibrary.simpleMessage("Color"),
"labelConversionLinePeriod": MessageLookupByLibrary.simpleMessage(
"Período de Línea de Conversión"),
"labelDistance": MessageLookupByLibrary.simpleMessage("Distancia"),
"labelDoubleSmoothingPeriod":
MessageLookupByLibrary.simpleMessage("Período de Doble Suavizado"),
"labelFastMAPeriod":
MessageLookupByLibrary.simpleMessage("Período MA Rápido"),
"labelField": MessageLookupByLibrary.simpleMessage("Campo"),
"labelFillColor":
MessageLookupByLibrary.simpleMessage("Color de Relleno"),
"labelHighPeriod": MessageLookupByLibrary.simpleMessage("Período Alto"),
"labelHistogram": MessageLookupByLibrary.simpleMessage("Histograma"),
"labelIsSmooth": MessageLookupByLibrary.simpleMessage("Es Suave"),
"labelJawOffset":
MessageLookupByLibrary.simpleMessage("Desplazamiento de Mandíbula"),
"labelJawPeriod":
MessageLookupByLibrary.simpleMessage("Período de Mandíbula"),
"labelLaggingSpanOffset": MessageLookupByLibrary.simpleMessage(
"Desplazamiento de Intervalo Retrasado"),
"labelLipsOffset":
MessageLookupByLibrary.simpleMessage("Desplazamiento de Labios"),
"labelLipsPeriod":
MessageLookupByLibrary.simpleMessage("Período de Labios"),
"labelLowPeriod": MessageLookupByLibrary.simpleMessage("Período Bajo"),
"labelMaxAF": MessageLookupByLibrary.simpleMessage("AF Máximo"),
"labelMinAF": MessageLookupByLibrary.simpleMessage("AF Mínimo"),
"labelOffset": MessageLookupByLibrary.simpleMessage("Desplazamiento"),
"labelOverBoughtPrice":
MessageLookupByLibrary.simpleMessage("Precio de Sobrecompra"),
"labelOverSoldPrice":
MessageLookupByLibrary.simpleMessage("Precio de Sobreventa"),
"labelPeriod": MessageLookupByLibrary.simpleMessage("Período"),
"labelSearchAssets":
MessageLookupByLibrary.simpleMessage("Buscar activos"),
"labelSeries": MessageLookupByLibrary.simpleMessage("Series"),
"labelShading": MessageLookupByLibrary.simpleMessage("Sombreado"),
"labelShift": MessageLookupByLibrary.simpleMessage("Desplazar"),
"labelShiftType":
MessageLookupByLibrary.simpleMessage("Tipo de Desplazamiento"),
"labelShowFractals":
MessageLookupByLibrary.simpleMessage("Mostrar Fractales"),
"labelShowLines":
MessageLookupByLibrary.simpleMessage("Mostrar Líneas"),
"labelShowZones": MessageLookupByLibrary.simpleMessage("Mostrar Zonas"),
"labelSignalPeriod":
MessageLookupByLibrary.simpleMessage("Período de Señal"),
"labelSlowMAPeriod":
MessageLookupByLibrary.simpleMessage("Período MA Lento"),
"labelSmoothingPeriod":
MessageLookupByLibrary.simpleMessage("Período de Suavizado"),
"labelSpanBPeriod": MessageLookupByLibrary.simpleMessage(
"Período de Intervalo B Principal"),
"labelStandardDeviation":
MessageLookupByLibrary.simpleMessage("Desviación Estándar"),
"labelTeethOffset":
MessageLookupByLibrary.simpleMessage("Desplazamiento de Dientes"),
"labelTeethPeriod":
MessageLookupByLibrary.simpleMessage("Período de Dientes"),
"labelType": MessageLookupByLibrary.simpleMessage("Tipo"),
"selectDrawingTool": MessageLookupByLibrary.simpleMessage(
"Seleccionar herramienta de dibujo"),
"warnCheckAssetSearchingText": MessageLookupByLibrary.simpleMessage(
"Intente verificar la ortografía o use un término diferente"),
"warnFailedLoadingDrawingTools": MessageLookupByLibrary.simpleMessage(
"Error al cargar las herramientas de dibujo."),
"warnFailedLoadingIndicators": MessageLookupByLibrary.simpleMessage(
"Error al cargar los indicadores.")
};
}
48 changes: 47 additions & 1 deletion lib/l10n/intl_es.arb
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
{
"@@locale": "es"
"@@locale": "es",
"labelChannelFill": "Relleno de Canal",
"labelShading": "Sombreado",
"labelHistogram": "Histograma",
"labelSeries": "Series",
"labelField": "Campo",
"labelPeriod": "Período",
"labelSmoothingPeriod": "Período de Suavizado",
"labelConversionLinePeriod": "Período de Línea de Conversión",
"labelBaseLinePeriod": "Período de Línea Base",
"labelDoubleSmoothingPeriod": "Período de Doble Suavizado",
"labelSpanBPeriod": "Período de Intervalo B Principal",
"labelLaggingSpanOffset": "Desplazamiento de Intervalo Retrasado",
"labelJawPeriod": "Período de Mandíbula",
"labelTeethPeriod": "Período de Dientes",
"labelLipsPeriod": "Período de Labios",
"labelOffset": "Desplazamiento",
"labelJawOffset": "Desplazamiento de Mandíbula",
"labelTeethOffset": "Desplazamiento de Dientes",
"labelLipsOffset": "Desplazamiento de Labios",
"labelHighPeriod": "Período Alto",
"labelLowPeriod": "Período Bajo",
"labelFastMAPeriod": "Período MA Rápido",
"labelSlowMAPeriod": "Período MA Lento",
"labelSignalPeriod": "Período de Señal",
"labelOverBoughtPrice": "Precio de Sobrecompra",
"labelOverSoldPrice": "Precio de Sobreventa",
"labelMaxAF": "AF Máximo",
"labelMinAF": "AF Mínimo",
"labelShift": "Desplazar",
"labelShowZones": "Mostrar Zonas",
"labelBandsCount": "Número de Bandas",
"labelSearchAssets": "Buscar activos",
"labelStandardDeviation": "Desviación Estándar",
"labelType": "Tipo",
"labelShiftType": "Tipo de Desplazamiento",
"labelDistance": "Distancia",
"informNoResult": "No hay resultados para \"{text}\"",
"warnCheckAssetSearchingText": "Intente verificar la ortografía o use un término diferente",
"labelShowLines": "Mostrar Líneas",
"labelShowFractals": "Mostrar Fractales",
"labelIsSmooth": "Es Suave",
"warnFailedLoadingIndicators": "Error al cargar los indicadores.",
"warnFailedLoadingDrawingTools": "Error al cargar las herramientas de dibujo.",
"selectDrawingTool": "Seleccionar herramienta de dibujo",
"labelColor": "Color",
"labelFillColor": "Color de Relleno"
}
13 changes: 10 additions & 3 deletions lib/src/deriv_chart/deriv_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ class _DerivChartState extends State<DerivChart> {
) =>
ChangeNotifierProvider<Repository<IndicatorConfig>>.value(
value: _indicatorsRepo,
child: IndicatorsDialog(),
child: LocalizationProvider(
localization: widget.localizations ?? ChartLocalization(),
child: IndicatorsDialog(),
),
),
);
}
Expand Down Expand Up @@ -303,8 +306,9 @@ class _DerivChartState extends State<DerivChart> {

@override
Widget build(BuildContext context) {
final chartLocalization = widget.localizations ?? ChartLocalization();
return LocalizationProvider(
localization: widget.localizations ?? ChartLocalization(),
localization: chartLocalization,
child: MultiProvider(
providers: <ChangeNotifierProvider<Repository<AddOnConfig>>>[
ChangeNotifierProvider<Repository<IndicatorConfig>>.value(
Expand All @@ -315,7 +319,9 @@ class _DerivChartState extends State<DerivChart> {
child: Builder(
builder: (BuildContext context) => Stack(
children: <Widget>[
Chart(
LocalizationProvider(
localization: chartLocalization,
child: Chart(
mainSeries: widget.mainSeries,
pipSize: widget.pipSize,
granularity: widget.granularity,
Expand Down Expand Up @@ -362,6 +368,7 @@ class _DerivChartState extends State<DerivChart> {
showScrollToLastTickButton: widget.showScrollToLastTickButton,
loadingAnimationColor: widget.loadingAnimationColor,
chartAxisConfig: widget.chartAxisConfig,
),
),
if (widget.indicatorsRepo == null) _buildIndicatorsIcon(),
if (widget.drawingToolsRepo == null) _buildDrawingToolsIcon(),
Expand Down
13 changes: 12 additions & 1 deletion lib/src/widgets/localization_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ class LocalizationProvider extends InheritedWidget {

static ChartLocalization of(BuildContext context) {
final provider = context.dependOnInheritedWidgetOfExactType<LocalizationProvider>();
return provider?.localization ?? ChartLocalization();
if (provider != null) {
return provider.localization;
}

// Fallback to Localizations if provider not found
final localization = Localizations.of<ChartLocalization>(context, ChartLocalization);
if (localization != null) {
return localization;
}

// If neither is available, create a new instance
return ChartLocalization();
}

@override
Expand Down

0 comments on commit 0c84e42

Please sign in to comment.