/*
 * Copyright 2018 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.template.soy.sharedpasses.render;

import com.google.template.soy.internal.i18n.BidiGlobalDir;
import com.google.template.soy.msgs.SoyMsgBundle;
import com.google.template.soy.plugin.java.restricted.JavaPluginContext;
import com.google.template.soy.plugin.java.restricted.JavaValue;

/** Exposes plugin context for Tofu, based on a SoyMsgBundle. */
final class TofuPluginContext implements JavaPluginContext {
  private final SoyMsgBundle msgBundle;

  public TofuPluginContext(SoyMsgBundle msgBundle) {
    this.msgBundle = msgBundle;
  }

  @Override
  public JavaValue getBidiDir() {
    return TofuJavaValue.forBidiDir(
        BidiGlobalDir.forStaticIsRtl(msgBundle == null ? false : msgBundle.isRtl()));
  }

  @Override
  public TofuJavaValue getULocale() {
    return TofuJavaValue.forULocale(msgBundle.getLocale());
  }
}

@@ -890,16 +890,83 @@
 vaValue;
+%0Aimport com.ibm.icu.util.ULocale;%0Aimport javax.annotation.Nullable;
 %0A%0A/** Ex
@@ -1087,16 +1087,26 @@
 ext %7B%0A  
+@Nullable 
 private 
@@ -1163,16 +1163,26 @@
 Context(
+@Nullable 
 SoyMsgBu
@@ -1505,16 +1505,54 @@
 sgBundle
+ == null ? ULocale.ENGLISH : msgBundle
 .getLoca

Make tofu plugin context provide a default for locale when there is no message bundle.